From 386ae33d805a6dbb4d7be225e3dfa1b34055246e Mon Sep 17 00:00:00 2001 From: snt Date: Wed, 4 Sep 2024 22:25:51 +0200 Subject: [PATCH] =?UTF-8?q?upgrade=20v16=20separaci=C3=B3n=20de=20las=20fu?= =?UTF-8?q?ncionalidades=20del=20PoS=20en=20un=20m=C3=B3dulo=20aparte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pos_product_library/__init__.py | 1 + pos_product_library/__manifest__.py | 30 +++++++++ pos_product_library/models/__init__.py | 2 + pos_product_library/models/pos_session.py | 15 +++++ pos_product_library/static/src/js/screens.js | 33 ++++++++++ pos_product_library/static/src/xml/pos.xml | 61 +++++++++++++++++ product_library/__manifest__.py | 17 +---- product_library/models/__init__.py | 4 +- product_library/models/pos_config.py | 16 ----- product_library/models/product_product.py | 22 ++----- product_library/models/product_template.py | 8 +-- product_library/static/src/css/pos.css | 39 ----------- product_library/static/src/js/db.js | 61 ----------------- product_library/static/src/js/models.js | 31 --------- product_library/static/src/js/widgets.js | 42 ------------ product_library/static/src/xml/pos.xml | 69 -------------------- product_library/views/pos_config.xml | 29 -------- product_library/views/product.xml | 57 +++++++++------- product_library/views/templates.xml | 33 ---------- 19 files changed, 184 insertions(+), 386 deletions(-) create mode 100644 pos_product_library/__init__.py create mode 100644 pos_product_library/__manifest__.py create mode 100644 pos_product_library/models/__init__.py create mode 100644 pos_product_library/models/pos_session.py create mode 100644 pos_product_library/static/src/js/screens.js create mode 100644 pos_product_library/static/src/xml/pos.xml delete mode 100644 product_library/models/pos_config.py delete mode 100644 product_library/static/src/css/pos.css delete mode 100644 product_library/static/src/js/db.js delete mode 100644 product_library/static/src/js/models.js delete mode 100644 product_library/static/src/js/widgets.js delete mode 100644 product_library/static/src/xml/pos.xml delete mode 100644 product_library/views/pos_config.xml delete mode 100644 product_library/views/templates.xml diff --git a/pos_product_library/__init__.py b/pos_product_library/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/pos_product_library/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_product_library/__manifest__.py b/pos_product_library/__manifest__.py new file mode 100644 index 0000000..0d9a6ed --- /dev/null +++ b/pos_product_library/__manifest__.py @@ -0,0 +1,30 @@ +{ + 'name': 'PoS Product Library', + 'category': 'Product', + 'summary': 'Add product_library fields to point of sale', + 'version': "16.0.1.0.0", + 'description': """ + +Añade los campos de product_library al TPV +================================================== +* Hace búsquedas en el TPV de los campos autor y género. +* Muestra el campo formato en el PoS en los productos y en las líneas de la orden. +* Muestra los campos de product_library en el popup de info del producto. +* Impide la búsqueda en el TPV en las descripciones. +""", + 'author': 'Criptomart', + 'depends': [ + 'product_library', + 'point_of_sale', + ], + "assets": { + "point_of_sale.assets": [ + "pos_product_library/static/src/js/**/*.js", + "pos_product_library/static/src/xml/**/*.xml", + ], + }, + 'demo': [], + 'installable': True, + 'auto_install': False, + 'application': True, +} diff --git a/pos_product_library/models/__init__.py b/pos_product_library/models/__init__.py new file mode 100644 index 0000000..b93c772 --- /dev/null +++ b/pos_product_library/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_session + diff --git a/pos_product_library/models/pos_session.py b/pos_product_library/models/pos_session.py new file mode 100644 index 0000000..6c39268 --- /dev/null +++ b/pos_product_library/models/pos_session.py @@ -0,0 +1,15 @@ +from odoo import models + + +class PosSession(models.Model): + _inherit = 'pos.session' + + def _loader_params_product_product(self): + result = super()._loader_params_product_product() + result['search_params']['fields'].append('formato') + result['search_params']['fields'].append('autor'); + result['search_params']['fields'].append('editorial'); + result['search_params']['fields'].append('genero'); + result['search_params']['fields'].append('subtitle'); + result['search_params']['fields'].append('fecha_entrada'); + return result diff --git a/pos_product_library/static/src/js/screens.js b/pos_product_library/static/src/js/screens.js new file mode 100644 index 0000000..b90804b --- /dev/null +++ b/pos_product_library/static/src/js/screens.js @@ -0,0 +1,33 @@ +odoo.define('product_library.screens', function (require) { + "use strict"; + + var ProductScreen = require('point_of_sale.ProductScreen'); + var Registries = require('point_of_sale.Registries'); + + const LibraryProductScreen = (ProductScreen) => + class extends ProductScreen { + _searchProduct(event) { + const query = event.target.value.trim().toLowerCase(); + if (query) { + const products = this.env.pos.db.get_product_by_category(0).filter(product => { + return product.display_name.toLowerCase().includes(query) || + product.autor.toLowerCase().includes(query) || + product.editorial.toLowerCase().includes(query); + }); + this.env.pos.db.add_products(products); + } else { + this.env.pos.db.add_products(this.env.pos.db.get_product_by_category(0)); + } + this.render(); + } + + mounted() { + super.mounted(); + this.el.querySelector('.searchbox input').addEventListener('input', this._searchProduct.bind(this)); + } + }; + + Registries.Component.extend(ProductScreen, LibraryProductScreen); + + return LibraryProductScreen; +}); \ No newline at end of file diff --git a/pos_product_library/static/src/xml/pos.xml b/pos_product_library/static/src/xml/pos.xml new file mode 100644 index 0000000..3716dda --- /dev/null +++ b/pos_product_library/static/src/xml/pos.xml @@ -0,0 +1,61 @@ + + + + +
+
+ +
+
+
+ + + +
+ Formato: +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/product_library/__manifest__.py b/product_library/__manifest__.py index fc8ce0b..96c156b 100644 --- a/product_library/__manifest__.py +++ b/product_library/__manifest__.py @@ -8,32 +8,17 @@ Addon mejora de Odoo para librerías y tiendas de discos ================================================== * Añade campos a product: Editorial, autor, género, formato, fecha de edición, fecha de entrada, colección, subcolección. -* Hace búsquedas en el TPV y backend en esos campos nuevos. -* Búsqueda sin acentos en el PoS. -* Muestra el campo formato en el PoS en los productos y en las líneas de la orden. -* Funcionalidad de pos_empty_default_image para mostrar el formato, en el addon original sobrescribe el widget y no se puede mostraar. - +* Hace búsquedas en la ficha de productos del backend en esos campos nuevos. """, 'author': 'Criptomart', 'depends': [ 'product', - 'point_of_sale', ], - 'external_dependencies': {'python': [], 'bin': []}, 'data': [ 'views/product.xml', - 'views/templates.xml', - 'views/pos_config.xml', - ], - 'qweb': [ - 'static/src/xml/pos.xml', ], 'demo': [], 'installable': True, 'auto_install': False, 'application': True, - "post_load": None, - "pre_init_hook": None, - "post_init_hook": None, - "uninstall_hook": None, } diff --git a/product_library/models/__init__.py b/product_library/models/__init__.py index 563faa7..3ec9018 100644 --- a/product_library/models/__init__.py +++ b/product_library/models/__init__.py @@ -1,5 +1,3 @@ -from . import pos_config from . import product_template -#from . import product_product - +from . import product_product diff --git a/product_library/models/pos_config.py b/product_library/models/pos_config.py deleted file mode 100644 index 1acbec4..0000000 --- a/product_library/models/pos_config.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2020 - Today: -# GRAP (http://www.grap.coop) -# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import models, fields - - -class PosConfig(models.Model): - _inherit = 'pos.config' - - iface_fixed_font_size = fields.Integer( - string="Fixed Font Size", - help="Font size of the product name, when it has no image." - " Set '0' will set adaptative font-size, depending on the" - " length of the name.") diff --git a/product_library/models/product_product.py b/product_library/models/product_product.py index c584498..7e6955b 100644 --- a/product_library/models/product_product.py +++ b/product_library/models/product_product.py @@ -1,19 +1,11 @@ -# Copyright (C) 2017 - Today: -# GRAP (http://www.grap.coop) -# Akretion (http://www.akretion.com) -# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import models, fields, api - +from odoo import models, fields class ProductProduct(models.Model): _inherit = 'product.product' - @api.depends('image') - def _compute_has_image(self): - for product in self: - product.has_image = product.image - - has_image = fields.Boolean( - compute='_compute_has_image', string='Has Image', store=True) + formato = fields.Char('Formato', related='product_tmpl_id.formato', store=True) + autor = fields.Char('Autor', related='product_tmpl_id.autor', store=True) + editorial = fields.Char('Editorial', related='product_tmpl_id.editorial', store=True) + genero = fields.Char('Genero', related='product_tmpl_id.genero', store=True) + subtitle = fields.Char('Subtitulo', related='product_tmpl_id.subtitle', store=True) + fecha_entrada = fields.Char('Fecha de entrada', related='product_tmpl_id.fecha_entrada', store=True) \ No newline at end of file diff --git a/product_library/models/product_template.py b/product_library/models/product_template.py index 59ca65d..bb66747 100644 --- a/product_library/models/product_template.py +++ b/product_library/models/product_template.py @@ -1,13 +1,8 @@ -# Copyright (C) 2021: Criptomart (https://criptomart.net) -# @author Santi Noreña () +# Copyright (C) 2021-2024: Criptomart (https://criptomart.net) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import logging - from odoo import tools, models, fields, api, _ -_logger = logging.getLogger(__name__) - class ProductTemplate(models.Model): _inherit = "product.template" @@ -17,7 +12,6 @@ class ProductTemplate(models.Model): pais_edicion = fields.Char('Pais de edicion') colacion = fields.Char('Colacion') autor = fields.Char('Autor') - isbn = fields.Char('ISBN') coleccion = fields.Char('Coleccion') subcoleccion = fields.Char('Subcoleccion') idioma = fields.Char('Idioma') diff --git a/product_library/static/src/css/pos.css b/product_library/static/src/css/pos.css deleted file mode 100644 index bca99ed..0000000 --- a/product_library/static/src/css/pos.css +++ /dev/null @@ -1,39 +0,0 @@ -.pos .product .format { - position: absolute; - top: 20px; - right: 2px; - vertical-align: top; - color: white; - line-height: 13px; - background: #7f82ac; - padding: 2px 5px; - border-radius: 2px; - font-weight: bold; -} - -.pos .order .orderline .format { - color: #57C; - font-weight: bold; - font-style: normal; -} - -/* - Copyright (C) 2014 - Today: GRAP (http://www.grap.coop) - @author Julien WESTE - @author: Sylvain LE GAL (https://twitter.com/legalsylvain) - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -*/ - -.product-img-without-image{ - height:25px !important; -} - -.product-name-without-image{ - bottom:auto !important; - top:25px !important; - padding-top:13px !important; - height:80px !important; - line-height: 20px; - text-align: center; - word-wrap: break-word; -} diff --git a/product_library/static/src/js/db.js b/product_library/static/src/js/db.js deleted file mode 100644 index 1194dec..0000000 --- a/product_library/static/src/js/db.js +++ /dev/null @@ -1,61 +0,0 @@ -odoo.define('product_library', function (require) { - - "use strict"; - var db = require("point_of_sale.DB"); - db.include({ - - normalize_characters: function (product) { - // The normalization extract out combining diacritical marks - // All those diacritics in range [\u0300-\u036f]. - // See https://en.wikipedia.org/wiki/Combining_Diacritical_Marks. - // All the diacritics are removed by the code below. - return product.normalize("NFD") - .replace(/[\u0300-\u036f]/g, "") - .replace(/[\u0152-\u0153]/g, "oe"); - }, - - add_custom_fields: function(product) { - if(product) { - var str = product.display_name; - if(product.default_code){ - str += '|' + product.default_code; - } - if(product.autor){ - str += '|' + product.autor; - } - if(product.genero){ - str += '|' + product.genero; - } - if(product.editorial){ - str += '|' + product.editorial; - } -/* - if (product.description) { - str += '|' + product.description; - } - if (product.description_sale) { - str += '|' + product.description_sale; - } -*/ - str = product.id + ':' + str.replace(':','') + '\n'; - } - return str; - }, - - _product_search_string: function(product) { - console.log("product : " + JSON.stringify(product, null, 4)); - var str = this.add_custom_fields(product); - console.log("string : " + str); - var norm = this.normalize_characters(str); - console.log("normalizado : " + norm); - return norm; - }, -/* - search_product_in_category: function (category_id, query) { - return this._super(category_id, this.add_custom_fields(query)); - },*/ - }); - - return db; - -}); diff --git a/product_library/static/src/js/models.js b/product_library/static/src/js/models.js deleted file mode 100644 index fea2671..0000000 --- a/product_library/static/src/js/models.js +++ /dev/null @@ -1,31 +0,0 @@ -odoo.define('product_library.product_library', function (require) { - "use strict"; - - var models = require('point_of_sale.models'); - //var screens = require('point_of_sale.screens'); - //var core = require('web.core'); - //var gui = require('point_of_sale.gui'); - //var _t = core._t; - - //models.load_fields("product.product", ['has_image']); - -/* ******************************************************** -Overload models.PosModel -******************************************************** */ - - var _super_posmodel = models.PosModel.prototype; - models.PosModel = models.PosModel.extend({ - initialize: function (session, attributes) { - - //this.member_categories = []; - - var product_model = _.find(this.models, function(model){ return model.model === 'product.product'; }); - //product_model.fields.push('default_code'); - product_model.fields.push('autor'); - product_model.fields.push('editorial'); - product_model.fields.push('genero'); - product_model.fields.push('formato'); - return _super_posmodel.initialize.apply(this, arguments); - } - }); -}); diff --git a/product_library/static/src/js/widgets.js b/product_library/static/src/js/widgets.js deleted file mode 100644 index 79aa672..0000000 --- a/product_library/static/src/js/widgets.js +++ /dev/null @@ -1,42 +0,0 @@ -odoo.define('product_library.widgets', function (require) { - "use strict"; - - var screens = require('point_of_sale.screens'); - - var core = require('web.core'); - - var QWeb = core.qweb; - - //don't try to get an image if we know the product ain't one - var ProductListImageWidget = screens.ProductListWidget.include({ - get_product_image_url: function(product){ - if (product.has_image) - return this._super(product); - }, - - // Change product display if product has no image; - render_product: function(product){ - if (product.has_image){ - return this._super(product); - } - else { - var current_pricelist = this._get_active_pricelist(); - var cache_key = this.calculate_cache_key(product, current_pricelist); - var cached = this.product_cache.get_node(cache_key); - if(!cached){ - var product_html = QWeb.render('ProductNoImage',{ - widget: this, - product: product, - pricelist: current_pricelist, - }); - var product_node = document.createElement('div'); - product_node.innerHTML = product_html; - product_node = product_node.childNodes[1]; - this.product_cache.cache_node(cache_key,product_node); - return product_node; - } - return cached; - } - }, - }); -}); diff --git a/product_library/static/src/xml/pos.xml b/product_library/static/src/xml/pos.xml deleted file mode 100644 index f6e8b3b..0000000 --- a/product_library/static/src/xml/pos.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - -
- -
- -
-
- -
- - diff --git a/product_library/views/pos_config.xml b/product_library/views/pos_config.xml deleted file mode 100644 index 2b82080..0000000 --- a/product_library/views/pos_config.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - diff --git a/product_library/views/product.xml b/product_library/views/product.xml index 210c30f..ec51e0a 100644 --- a/product_library/views/product.xml +++ b/product_library/views/product.xml @@ -1,29 +1,36 @@ - - product.template.library.form - product.template - - - - - - - - - - - - - - - - -
-
-
+ + product.template.library.form + product.template + + + + + + + + + + + + + + + - +
+
+ + product.template.search.library + product.template + + + + + + + + +
diff --git a/product_library/views/templates.xml b/product_library/views/templates.xml deleted file mode 100644 index fe442f2..0000000 --- a/product_library/views/templates.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - -
Formato:
Subtitulo:
Autor:
Editorial:
Entrada:
Género: