diff --git a/pos_remove_pos_category/README.rst b/pos_remove_pos_category/README.rst new file mode 100644 index 00000000..bcdee09d --- /dev/null +++ b/pos_remove_pos_category/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +POS Remove POS Category +======================= + +This module was written to replace POS categories by product categories +in the point of sale. + +Important notes +--------------- +- When the module is installed the link beetween products and POS categories + is **overwritten** by a link beetween products and product categories + (the link is the field pos_categ_id in the table product_template) +- When the module is uninstalled the link beetween products and POS categories + is restored in an **empty** state (NULL values) + +Installation +============ + +This module depends on the `point_of_sale` Odoo official module. + +Configuration +============= + +No configuration is needed just use product categories as standard +pos categories. +You may uncheck 'Available in the Point of Sale' field +in regular product categories if you want that a category becomes invisible +in POS. +Children categories will becomes invisible too, whatever their checkbox state. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Sylvain Calador +* Simone Orsi + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/pos_remove_pos_category/__init__.py b/pos_remove_pos_category/__init__.py new file mode 100644 index 00000000..d5e4731a --- /dev/null +++ b/pos_remove_pos_category/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015-TODAY Akretion (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/pos_remove_pos_category/__openerp__.py b/pos_remove_pos_category/__openerp__.py new file mode 100644 index 00000000..87eec41b --- /dev/null +++ b/pos_remove_pos_category/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015-TODAY Akretion (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'POS Remove POS Category', + 'version': '9.0.0.1.0', + 'author': 'Akretion, Camptocamp SA, Odoo Community Association (OCA)', + 'category': 'Sales Management', + 'depends': [ + 'point_of_sale', + ], + 'demo': [], + 'website': 'https://www.akretion.com', + 'data': [ + 'views/assets.xml', + 'views/pos_view.xml', + 'views/pos_category_view.xml', + ], + 'installable': True, +} diff --git a/pos_remove_pos_category/i18n/ca.po b/pos_remove_pos_category/i18n/ca.po new file mode 100644 index 00000000..7d905a2f --- /dev/null +++ b/pos_remove_pos_category/i18n/ca.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_remove_pos_category +# +# Translators: +# Marc Tormo i Bochaca , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-03-28 05:50+0000\n" +"PO-Revision-Date: 2017-03-28 05:50+0000\n" +"Last-Translator: Marc Tormo i Bochaca , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: ca\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: pos_remove_pos_category +#: model:ir.ui.view,arch_db:pos_remove_pos_category.product_category_list_view +msgid "Available in POS" +msgstr "Disponible al TPV" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_available_in_pos +msgid "Available in the Point of Sale" +msgstr "Disponible al Punt de Venda " + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_available_in_pos +msgid "" +"Check if you want this category to appear in Point Of Sale.\n" +"If you uncheck, children categories will becomes invisible too, whatever their checkbox state." +msgstr "" +"Marqueu si voleu que aquesta categoria aparegui al Punt de Venda.\n" +"Si el desmarqueu, les categories filles també es tornaran invisibles, encara que estiguin marcades. " + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image +msgid "Image" +msgstr "Imatge" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image_medium +msgid "Image medium" +msgstr "Imatge mitjana " + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_ir_module_module +msgid "Module" +msgstr "Mòdul " + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_category +msgid "Product Category" +msgstr "Categoria de Producte " + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_template +msgid "Product Template" +msgstr "Plantilla de Producte " + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image +msgid "Show Image Category in Form View" +msgstr "Mostra la imatge de la categoria a la vista del formulari " + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image_medium +msgid "Show image category button in POS" +msgstr "Mostra la imatge de la categoria al TPV " diff --git a/pos_remove_pos_category/i18n/fr.po b/pos_remove_pos_category/i18n/fr.po new file mode 100644 index 00000000..738cb1b2 --- /dev/null +++ b/pos_remove_pos_category/i18n/fr.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_remove_pos_category +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-03-01 04:05+0000\n" +"PO-Revision-Date: 2017-03-01 04:05+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: pos_remove_pos_category +#: model:ir.ui.view,arch_db:pos_remove_pos_category.product_category_list_view +msgid "Available in POS" +msgstr "Disponible dans le PDV" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_available_in_pos +msgid "Available in the Point of Sale" +msgstr "Disponible dans le Point de Vente" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_available_in_pos +msgid "" +"Check if you want this category to appear in Point Of Sale.\n" +"If you uncheck, children categories will becomes invisible too, whatever their checkbox state." +msgstr "" +"Cochez si vous voulez que cette catégorie apparaisse dans le Point de Vente.\n" +"Si vous décochez, les catégories enfants deviendront invisible également, quel que soit l'état de leur case à cocher." + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image +msgid "Image" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image_medium +msgid "Image medium" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_ir_module_module +msgid "Module" +msgstr "Module" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_category +msgid "Product Category" +msgstr "Catégorie de Produit" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_template +msgid "Product Template" +msgstr "Modèle d'article" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image +msgid "Show Image Category in Form View" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image_medium +msgid "Show image category button in POS" +msgstr "" diff --git a/pos_remove_pos_category/i18n/it.po b/pos_remove_pos_category/i18n/it.po new file mode 100644 index 00000000..6219fde9 --- /dev/null +++ b/pos_remove_pos_category/i18n/it.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_remove_pos_category +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-03-01 04:05+0000\n" +"PO-Revision-Date: 2017-03-01 04:05+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: pos_remove_pos_category +#: model:ir.ui.view,arch_db:pos_remove_pos_category.product_category_list_view +msgid "Available in POS" +msgstr "Disponibile nel POS" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_available_in_pos +msgid "Available in the Point of Sale" +msgstr "Disponibile nel POS" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_available_in_pos +msgid "" +"Check if you want this category to appear in Point Of Sale.\n" +"If you uncheck, children categories will becomes invisible too, whatever their checkbox state." +msgstr "" +"Attiva per far apparire questa categoria nel POS.\n" +"Se disattivato, anche le sotto-categorie saranno nascoste, anche se attivate singolarmente." + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image +msgid "Image" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,field_description:pos_remove_pos_category.field_product_category_image_medium +msgid "Image medium" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_ir_module_module +msgid "Module" +msgstr "Module" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_category +msgid "Product Category" +msgstr "Categoria Prodotto" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_template +msgid "Product Template" +msgstr "Template Prodotto" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image +msgid "Show Image Category in Form View" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model.fields,help:pos_remove_pos_category.field_product_category_image_medium +msgid "Show image category button in POS" +msgstr "" diff --git a/pos_remove_pos_category/i18n/pos_remove_pos_category.pot b/pos_remove_pos_category/i18n/pos_remove_pos_category.pot new file mode 100644 index 00000000..752acaeb --- /dev/null +++ b/pos_remove_pos_category/i18n/pos_remove_pos_category.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_remove_pos_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-24 07:13+0000\n" +"PO-Revision-Date: 2015-07-24 07:13+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_remove_pos_category +#: view:product.category:pos_remove_pos_category.product_category_list_view +msgid "Available in POS" +msgstr "" + +#. module: pos_remove_pos_category +#: field:product.category,available_in_pos:0 +msgid "Available in the Point of Sale" +msgstr "" + +#. module: pos_remove_pos_category +#: help:product.category,available_in_pos:0 +msgid "Check if you want this category to appear in Point Of Sale.\n" +"If you uncheck, children categories will becomes invisible too, whatever their checkbox state." +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_ir_module_module +msgid "Module" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_category +msgid "Product Category" +msgstr "" + +#. module: pos_remove_pos_category +#: model:ir.model,name:pos_remove_pos_category.model_product_template +msgid "Product Template" +msgstr "" diff --git a/pos_remove_pos_category/models/__init__.py b/pos_remove_pos_category/models/__init__.py new file mode 100644 index 00000000..af4a9dcf --- /dev/null +++ b/pos_remove_pos_category/models/__init__.py @@ -0,0 +1,2 @@ +from . import module +from . import product diff --git a/pos_remove_pos_category/models/module.py b/pos_remove_pos_category/models/module.py new file mode 100644 index 00000000..3b12e6f0 --- /dev/null +++ b/pos_remove_pos_category/models/module.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015-TODAY Akretion (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models + + +class Module(models.Model): + + _inherit = 'ir.module.module' + + def module_uninstall(self, cr, uid, ids, context=None): + + context = context or {} + + for module in self.browse(cr, uid, ids, context=context): + if module.name == 'pos_remove_pos_category': + + # As we have loose previous POS categs restore them + # in a sane empty state + + cr.execute('UPDATE product_template SET pos_categ_id=NULL') + + # And restore original constraint + cr.execute(''' + ALTER TABLE product_template + DROP CONSTRAINT IF EXISTS + product_template_pos_categ_id_fkey + ''') + + cr.execute(''' + ALTER TABLE product_template ADD CONSTRAINT + "product_template_pos_categ_id_fkey" + FOREIGN KEY (pos_categ_id) + REFERENCES pos_category(id) ON DELETE SET NULL; + ''') + + # Restore POS category menu action + # in SQL because pool/env is not available here + cr.execute(''' + UPDATE ir_act_window iaw SET res_model='pos.category' + FROM ir_model_data imd + WHERE + iaw.id = imd.res_id AND + imd.model = 'ir.actions.act_window' AND + imd.name = 'product_pos_category_action' + ''') + + break + + return super(Module, self).module_uninstall( + cr, uid, ids, context=context + ) diff --git a/pos_remove_pos_category/models/product.py b/pos_remove_pos_category/models/product.py new file mode 100644 index 00000000..52fc0e8e --- /dev/null +++ b/pos_remove_pos_category/models/product.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2015-TODAY Akretion (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import sys +from openerp import models, fields, api, tools + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + pos_categ_id = fields.Many2one('product.category', + store=True, related='categ_id') + + @api.model + def create(self, vals): + if 'categ_id' in vals: + vals['pos_categ_id'] = vals['categ_id'] + return super(ProductTemplate, self).create(vals) + + @api.multi + def write(self, vals): + if 'pos_categ_id' in vals and not vals['pos_categ_id']: + del vals['pos_categ_id'] + return super(ProductTemplate, self).write(vals) + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + image = fields.Binary(help='Show Image Category in Form View') + image_medium = fields.Binary(help='Show image category button in POS', + compute="_get_image", + inverse="_set_image", + store=True) + available_in_pos = fields.Boolean( + string="Available in the Point of Sale", + default=True, + help="Check if you want this category to appear in Point Of Sale.\n" + "If you uncheck, children categories will becomes invisible too, " + "whatever their checkbox state.") + + @api.multi + def _get_image(self): + return dict( + (rec.id, tools.image_get_resized_images(rec.image)) for rec in + self) + + @api.one + def _set_image(self): + return self.write( + {'image': tools.image_resize_image_big(self.image_medium)}) + + +_auto_end_original = models.BaseModel._auto_end + + +def _auto_end(self, cr, context=None): + """ Create the foreign keys recorded by _auto_init. + (pos_remove_pos_category monkey patching) + """ + context = context or {} + module = context['module'] + foreign_keys = [] + patched = 'openerp.addons.pos_remove_pos_category' in sys.modules + + for t, k, r, d in self._foreign_keys: + if patched and (t, k) == ('product_template', 'pos_categ_id'): + if module == 'pos_remove_pos_category': + cr.execute(''' + ALTER TABLE product_template + DROP CONSTRAINT IF EXISTS + product_template_pos_categ_id_fkey + ''') + cr.execute(''' + UPDATE product_template + SET pos_categ_id = categ_id; + ''') + cr.execute(''' + ALTER TABLE product_template ADD CONSTRAINT + "product_template_pos_categ_id_fkey" + FOREIGN KEY (pos_categ_id) + REFERENCES product_category(id) ON DELETE SET NULL; + ''') + continue + foreign_keys.append((t, k, r, d)) + self._foreign_keys = foreign_keys + return _auto_end_original(self, cr, context=context) + + +models.BaseModel._auto_end = _auto_end diff --git a/pos_remove_pos_category/static/src/js/pos_remove_pos_category.js b/pos_remove_pos_category/static/src/js/pos_remove_pos_category.js new file mode 100644 index 00000000..fc1b2ad3 --- /dev/null +++ b/pos_remove_pos_category/static/src/js/pos_remove_pos_category.js @@ -0,0 +1,38 @@ +/****************************************************************************** + * Copyright (C) 2015-2016 Akretion (). + * Copyright (C) 2017-TODAY Camptocamp SA (). + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + ******************************************************************************/ + +odoo.define('pos_remove_pos_category.remove_pos_category', function (require) { + "use strict"; + + var core = require('web.core'); + var pos_models = require('point_of_sale.models'); + var pos_screens = require('point_of_sale.screens'); + var Model = require('web.DataModel'); + var _t = core._t; + + var _pos_super = pos_models.PosModel.prototype; + pos_models.PosModel = pos_models.PosModel.extend({ + initialize: function(session, attributes) { + for (var i = 0 ; i < this.models.length; i++){ + if (this.models[i].model == 'pos.category') { + this.models[i].model = 'product.category'; + this.models[i].domain = [['available_in_pos', '=', true]]; + } + } + return _pos_super.initialize.apply(this, arguments); + } + }); + + // override method js POS (widgets.js) + // change pos.category by product.category + pos_screens.ProductCategoriesWidget.include({ + get_image_url: function(category){ + var image_url = '/web/binary/image?model=product.category&field=image_medium&id='; + return window.location.origin + image_url + category.id; + } + }); + +}); diff --git a/pos_remove_pos_category/views/assets.xml b/pos_remove_pos_category/views/assets.xml new file mode 100644 index 00000000..5cb4e69a --- /dev/null +++ b/pos_remove_pos_category/views/assets.xml @@ -0,0 +1,9 @@ + + + + diff --git a/pos_remove_pos_category/views/pos_category_view.xml b/pos_remove_pos_category/views/pos_category_view.xml new file mode 100644 index 00000000..f33d0613 --- /dev/null +++ b/pos_remove_pos_category/views/pos_category_view.xml @@ -0,0 +1,30 @@ + + + + product.category + + + 20 + + + + + + + + + + + + product.category + + + + + + + + diff --git a/pos_remove_pos_category/views/pos_view.xml b/pos_remove_pos_category/views/pos_view.xml new file mode 100644 index 00000000..c8e3cc54 --- /dev/null +++ b/pos_remove_pos_category/views/pos_view.xml @@ -0,0 +1,17 @@ + + + + product.template.form.inherit + product.template + + + + + 1 + + + + + product.category + +