From f6023acc5ae986aba3859f8141c92713f03fc0cc Mon Sep 17 00:00:00 2001 From: santiky Date: Mon, 9 Aug 2021 00:51:47 +0200 Subject: [PATCH] =?UTF-8?q?product=5Fcategory=5Ftax,=20configura=20impuest?= =?UTF-8?q?os=20por=20cada=20categor=C3=ADa=20de=20producto.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 | 29 +++++++++++++++++++ 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 +++++++++++++++++ 9 files changed, 143 insertions(+) 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_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..db9d165 --- /dev/null +++ b/product_category_tax/models/product_product.py @@ -0,0 +1,29 @@ +# 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) + category = template.categ_id + template.taxes_id = category.sell_tax_id + template.supplier_taxes_id = category.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 + + +
+
+
+ +
+
+
+
+
+
+
+