From a26a8e2c323214ec16ede64e7689bf5f84d4b535 Mon Sep 17 00:00:00 2001 From: santiky Date: Thu, 24 Mar 2022 11:04:28 +0100 Subject: [PATCH] =?UTF-8?q?a=C3=B1adidos=20tax=20y=20pos=5Fcategory=20por?= =?UTF-8?q?=20defecto=20by=20category?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- product_category_default_pos_cat/__init__.py | 1 + .../__manifest__.py | 20 ++++++++++ .../models/__init__.py | 4 ++ .../models/product_category.py | 15 +++++++ .../models/product_product.py | 40 +++++++++++++++++++ .../models/res_company.py | 13 ++++++ .../models/res_config_settings.py | 13 ++++++ .../views/product_category.xml | 16 ++++++++ .../views/res_config_settings_views.xml | 26 ++++++++++++ product_category_tax/__init__.py | 1 + product_category_tax/__manifest__.py | 20 ++++++++++ product_category_tax/models/__init__.py | 4 ++ .../models/product_category.py | 19 +++++++++ .../models/product_product.py | 35 ++++++++++++++++ product_category_tax/models/res_company.py | 13 ++++++ .../models/res_config_settings.py | 13 ++++++ .../views/product_category.xml | 17 ++++++++ .../views/res_config_settings_views.xml | 27 +++++++++++++ 18 files changed, 297 insertions(+) create mode 100644 product_category_default_pos_cat/__init__.py create mode 100644 product_category_default_pos_cat/__manifest__.py create mode 100644 product_category_default_pos_cat/models/__init__.py create mode 100644 product_category_default_pos_cat/models/product_category.py create mode 100644 product_category_default_pos_cat/models/product_product.py create mode 100644 product_category_default_pos_cat/models/res_company.py create mode 100644 product_category_default_pos_cat/models/res_config_settings.py create mode 100644 product_category_default_pos_cat/views/product_category.xml create mode 100644 product_category_default_pos_cat/views/res_config_settings_views.xml create mode 100644 product_category_tax/__init__.py create mode 100644 product_category_tax/__manifest__.py create mode 100644 product_category_tax/models/__init__.py create mode 100644 product_category_tax/models/product_category.py create mode 100644 product_category_tax/models/product_product.py create mode 100644 product_category_tax/models/res_company.py create mode 100644 product_category_tax/models/res_config_settings.py create mode 100644 product_category_tax/views/product_category.xml create mode 100644 product_category_tax/views/res_config_settings_views.xml diff --git a/product_category_default_pos_cat/__init__.py b/product_category_default_pos_cat/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/product_category_default_pos_cat/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_category_default_pos_cat/__manifest__.py b/product_category_default_pos_cat/__manifest__.py new file mode 100644 index 0000000..22438bc --- /dev/null +++ b/product_category_default_pos_cat/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Product Category Default PoS Category', + 'version': '12.0.1.0.0', + 'author': "Criptomart", + 'website': 'https://github.com/criptomart/obook', + 'license': 'AGPL-3', + 'category': 'Product', + 'depends': [ + 'product', + 'point_of_sale' + ], + 'data': [ + 'views/product_category.xml', + 'views/res_config_settings_views.xml', + ], + 'installable': True, +} diff --git a/product_category_default_pos_cat/models/__init__.py b/product_category_default_pos_cat/models/__init__.py new file mode 100644 index 0000000..ca02c74 --- /dev/null +++ b/product_category_default_pos_cat/models/__init__.py @@ -0,0 +1,4 @@ +from . import res_company +from . import res_config_settings +from . import product_product +from . import product_category diff --git a/product_category_default_pos_cat/models/product_category.py b/product_category_default_pos_cat/models/product_category.py new file mode 100644 index 0000000..76d54be --- /dev/null +++ b/product_category_default_pos_cat/models/product_category.py @@ -0,0 +1,15 @@ +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + pos_categ_id = fields.Many2one( + comodel_name="pos.category", string="Categoría en el Punto de Venta", + help="Configura los productos nuevos de ésta categoría, a la categoría del punto de venta definido aquí.", + ) + diff --git a/product_category_default_pos_cat/models/product_product.py b/product_category_default_pos_cat/models/product_product.py new file mode 100644 index 0000000..2aa2ac6 --- /dev/null +++ b/product_category_default_pos_cat/models/product_product.py @@ -0,0 +1,40 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +#import logging + +from odoo import _, api, fields, models + +#_logger = logging.getLogger(__name__) + +class ProductProduct(models.Model): + _inherit = 'product.product' + + + @api.model + def create(self, vals): + category = self.env['product.category'] + categ_id = vals.get("categ_id") + template_id = vals.get("product_tmpl_id") + if categ_id: + category = category.browse(categ_id) + vals['pos_categ_id'] = self.get_category_pos_category(category) + vals['available_in_pos'] = True + elif template_id: + template = self.env["product.template"].browse(template_id) + category = template.categ_id + template.pos_categ_id = self.get_category_pos_category(category) + if template.pos_categ_id: + template.available_in_pos = True + + return super().create(vals) + + @api.model + def get_category_pos_category(self, category=False): + cat = category + if self.env.user.company_id.use_parent_categories_to_determine_pos_categ: + while not cat.pos_categ_id and cat.parent_id: + cat = cat.parent_id + + return cat.pos_categ_id + diff --git a/product_category_default_pos_cat/models/res_company.py b/product_category_default_pos_cat/models/res_company.py new file mode 100644 index 0000000..0919091 --- /dev/null +++ b/product_category_default_pos_cat/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Company(models.Model): + _inherit = 'res.company' + + use_parent_categories_to_determine_pos_categ = fields.Boolean( + string="Use parent categories to determine the pos category", + help="Use parent categories to determine the pos category if the category has no settings for the PoS category.", + ) diff --git a/product_category_default_pos_cat/models/res_config_settings.py b/product_category_default_pos_cat/models/res_config_settings.py new file mode 100644 index 0000000..a394a4a --- /dev/null +++ b/product_category_default_pos_cat/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + use_parent_categories_to_determine_pos_categ = fields.Boolean( + related="company_id.use_parent_categories_to_determine_pos_categ", + readonly=False, + ) diff --git a/product_category_default_pos_cat/views/product_category.xml b/product_category_default_pos_cat/views/product_category.xml new file mode 100644 index 0000000..5d20598 --- /dev/null +++ b/product_category_default_pos_cat/views/product_category.xml @@ -0,0 +1,16 @@ + + + + + + product.category.form - product_category_pos_categ + product.category + + + + + + + + + diff --git a/product_category_default_pos_cat/views/res_config_settings_views.xml b/product_category_default_pos_cat/views/res_config_settings_views.xml new file mode 100644 index 0000000..50d4143 --- /dev/null +++ b/product_category_default_pos_cat/views/res_config_settings_views.xml @@ -0,0 +1,26 @@ + + + + res.config.settings.view.form.inherit.product + res.config.settings + + +
+
+
+ +
+
+
+
+
+
+
+ +
diff --git a/product_category_tax/__init__.py b/product_category_tax/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/product_category_tax/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_category_tax/__manifest__.py b/product_category_tax/__manifest__.py new file mode 100644 index 0000000..2383ec5 --- /dev/null +++ b/product_category_tax/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Product Category Tax', + 'version': '12.0.1.0.0', + 'author': "Criptomart", + 'website': 'https://github.com/criptomart/obook', + 'license': 'AGPL-3', + 'category': 'Product', + 'depends': [ + 'product', + 'account' + ], + 'data': [ + 'views/product_category.xml', + 'views/res_config_settings_views.xml', + ], + 'installable': True, +} diff --git a/product_category_tax/models/__init__.py b/product_category_tax/models/__init__.py new file mode 100644 index 0000000..ca02c74 --- /dev/null +++ b/product_category_tax/models/__init__.py @@ -0,0 +1,4 @@ +from . import res_company +from . import res_config_settings +from . import product_product +from . import product_category diff --git a/product_category_tax/models/product_category.py b/product_category_tax/models/product_category.py new file mode 100644 index 0000000..a7c0e35 --- /dev/null +++ b/product_category_tax/models/product_category.py @@ -0,0 +1,19 @@ +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + sell_tax_id = fields.Many2one( + comodel_name="account.tax", string="Impuesto de venta del producto", + help="Configura los productos de ésta categoría al impuesto definido aquí.", + ) + + buy_tax_id = fields.Many2one( + comodel_name="account.tax", string="Impuesto de compra del producto", + help="Configura los productos de ésta categoría al impuesto definido aquí.", + ) diff --git a/product_category_tax/models/product_product.py b/product_category_tax/models/product_product.py new file mode 100644 index 0000000..2b827e5 --- /dev/null +++ b/product_category_tax/models/product_product.py @@ -0,0 +1,35 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + +from odoo import _, api, fields, models + +_logger = logging.getLogger(__name__) + +class ProductProduct(models.Model): + _inherit = 'product.product' + + + @api.model + def create(self, vals): + category = self.env['product.category'] + categ_id = vals.get("categ_id") + template_id = vals.get("product_tmpl_id") + if categ_id: + category = category.browse(categ_id) + vals['taxes_id'] = category.sell_tax_id + vals['supplier_taxes_id'] = category.buy_tax_id + elif template_id: + template = self.env["product.template"].browse(template_id) + cat = template.categ_id + if self.env.user.company_id.use_parent_categories_to_determine_taxes: + while not cat.pos_categ_id and cat.parent_id: + cat = cat.parent_id + if cat: + template.taxes_id = cat.sell_tax_id + template.supplier_taxes_id = cat.buy_tax_id + + return super(ProductProduct, self).create(vals) + + diff --git a/product_category_tax/models/res_company.py b/product_category_tax/models/res_company.py new file mode 100644 index 0000000..ac8ab33 --- /dev/null +++ b/product_category_tax/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Company(models.Model): + _inherit = 'res.company' + + use_parent_categories_to_determine_taxes = fields.Boolean( + string="Use parent categories to determine the taxes", + help="Use parent categories to determine the taxes if the category has no settings for the taxes.", + ) diff --git a/product_category_tax/models/res_config_settings.py b/product_category_tax/models/res_config_settings.py new file mode 100644 index 0000000..d52d700 --- /dev/null +++ b/product_category_tax/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2021 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + use_parent_categories_to_determine_taxes = fields.Boolean( + related="company_id.use_parent_categories_to_determine_taxes", + readonly=False, + ) diff --git a/product_category_tax/views/product_category.xml b/product_category_tax/views/product_category.xml new file mode 100644 index 0000000..3b2c406 --- /dev/null +++ b/product_category_tax/views/product_category.xml @@ -0,0 +1,17 @@ + + + + + + product.category.form - product_category_tax + product.category + + + + + + + + + + diff --git a/product_category_tax/views/res_config_settings_views.xml b/product_category_tax/views/res_config_settings_views.xml new file mode 100644 index 0000000..1cc3a11 --- /dev/null +++ b/product_category_tax/views/res_config_settings_views.xml @@ -0,0 +1,27 @@ + + + + + res.config.settings.view.form.inherit.product + res.config.settings + + +
+
+
+ +
+
+
+
+
+
+
+