Skip to content

Commit

Permalink
Merge PR #23 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by peluko00
  • Loading branch information
OCA-git-bot committed Nov 13, 2024
2 parents 2554135 + 70d586e commit caba8e6
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bookstore_mgmt_google_books_api/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "AGPL-3",
"maintainers": ["peluko00", "miquelalzanillas"],
"version": "17.0.1.0.0",
"depends": ["bookstore_mgmt", "web_notify", "stock"],
"depends": ["bookstore_mgmt", "web_notify"],
"external_dependencies": {
"python": ["google-books-api-wrapper", "Unidecode"],
},
Expand Down
22 changes: 15 additions & 7 deletions bookstore_mgmt_google_books_api/i18n/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-06 14:45+0000\n"
"PO-Revision-Date: 2024-11-06 14:45+0000\n"
"POT-Creation-Date: 2024-11-13 15:45+0000\n"
"PO-Revision-Date: 2024-11-13 15:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "Book data updated from Google Books API"
msgstr "Dades actualitzades des de l'API de Google Books"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "ISBN code is mandatory. Please, provide one."
msgstr "El codi ISBN és obligatori. Si us plau, proporcioneu-ne un."
Expand All @@ -38,7 +39,8 @@ msgstr "Importa la informació del llibre"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "Not book found with this data"
msgstr "No s'ha trobat cap llibre amb aquestes dades"
Expand All @@ -48,9 +50,15 @@ msgstr "No s'ha trobat cap llibre amb aquestes dades"
msgid "Product"
msgstr "Producte"

#. module: bookstore_mgmt_google_books_api
#: model:ir.model,name:bookstore_mgmt_google_books_api.model_product_product
msgid "Product Variant"
msgstr "Variant de producte"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#: code:addons/bookstore_mgmt_google_books_api/tests/test_google_books_api.py:0
#, python-format
msgid "Warning"
Expand Down
22 changes: 15 additions & 7 deletions bookstore_mgmt_google_books_api/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-06 14:45+0000\n"
"PO-Revision-Date: 2024-11-06 14:45+0000\n"
"POT-Creation-Date: 2024-11-13 15:45+0000\n"
"PO-Revision-Date: 2024-11-13 15:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "Book data updated from Google Books API"
msgstr "Datos actualizados desde la API de Google Libros"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "ISBN code is mandatory. Please, provide one."
msgstr "El código ISBN es obligatorio. Por favor, proporcione uno."
Expand All @@ -38,7 +39,8 @@ msgstr "Importar datos del libro"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#, python-format
msgid "Not book found with this data"
msgstr "No se ha encontrado ningún libro con estos datos"
Expand All @@ -48,9 +50,15 @@ msgstr "No se ha encontrado ningún libro con estos datos"
msgid "Product"
msgstr "Producto"

#. module: bookstore_mgmt_google_books_api
#: model:ir.model,name:bookstore_mgmt_google_books_api.model_product_product
msgid "Product Variant"
msgstr "Variante de producto"

#. module: bookstore_mgmt_google_books_api
#. odoo-python
#: code:addons/bookstore_mgmt_google_books_api/models/product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_product.py:0
#: code:addons/bookstore_mgmt_google_books_api/models/product_template.py:0
#: code:addons/bookstore_mgmt_google_books_api/tests/test_google_books_api.py:0
#, python-format
msgid "Warning"
Expand Down
3 changes: 2 additions & 1 deletion bookstore_mgmt_google_books_api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import product
from . import product_product
from . import product_template
79 changes: 79 additions & 0 deletions bookstore_mgmt_google_books_api/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2024 (APSL-Nagarro) - Miquel Alzanillas, Antoni Marroig
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime

from google_books_api_wrapper.api import GoogleBooksAPI

from odoo import _, models
from odoo.exceptions import UserError


class Product(models.Model):
_inherit = "product.product"

def action_import_from_isbn(self):
for record in self.filtered(lambda x: x.is_book):
if record.barcode:
client = GoogleBooksAPI()
isbn = record.barcode.replace("-", "")
book = client.get_book_by_isbn13(isbn)
if not book:
book = client.get_book_by_isbn10(isbn)
if book:
# Set data to be updated
data = {
"name": book.title,
}

if book.published_date:
# Convert to year format
try:
published_year = datetime.strptime(
book.published_date, "%Y-%m-%d"
).year
except Exception:
published_year = book.published_date

data["year_edition"] = published_year

if book.authors:
data["author_id"] = record.get_author_id(book.authors[0])

if book.publisher:
data["editorial_id"] = record.get_editorial_id(book.publisher)

if book.subjects:
data["genre_id"] = record.get_genre_id(book.subjects)

if book.description:
data["description"] = book.description
data["description_sale"] = book.description

if book.large_thumbnail:
data["image_1920"] = record.get_convert_to_base64(
book.large_thumbnail
)

# Update book data in Odoo
record.write(data)

# Show success notification
self.env.user.notify_success(
message=_("Book data updated from Google Books API")
)

else:
# Return not found notification
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Warning"),
"type": "warning",
"message": _("Not book found with this data"),
"sticky": True,
},
}
else:
raise UserError(_("ISBN code is mandatory. Please, provide one."))

0 comments on commit caba8e6

Please sign in to comment.