From f0e574278ca0210278765a29617ac86d83414023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Mon, 5 Feb 2024 23:03:59 -0300 Subject: [PATCH] MIG] l10n_br_sale: Migration to 16.0 --- l10n_br_sale/__manifest__.py | 4 +-- l10n_br_sale/models/sale_order.py | 28 +++---------------- l10n_br_sale/models/sale_order_line.py | 18 +++++++----- l10n_br_sale/tests/test_l10n_br_sale.py | 3 -- .../tests/test_l10n_br_sale_discount.py | 8 +++++- .../tests/test_l10n_br_sale_pricelist.py | 2 -- l10n_br_sale/views/sale_view.xml | 12 ++++---- 7 files changed, 31 insertions(+), 44 deletions(-) diff --git a/l10n_br_sale/__manifest__.py b/l10n_br_sale/__manifest__.py index f1418527cd0b..30da3d3c7a40 100644 --- a/l10n_br_sale/__manifest__.py +++ b/l10n_br_sale/__manifest__.py @@ -7,7 +7,7 @@ "license": "AGPL-3", "author": "Akretion, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-brazil", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "depends": ["sale_management", "l10n_br_account"], "data": [ # Data @@ -33,5 +33,5 @@ "auto_install": True, "post_init_hook": "post_init_hook", "development_status": "Beta", - "maintainers": ["renatonlima"], + "maintainers": ["renatonlima", "rvalyi"], } diff --git a/l10n_br_sale/models/sale_order.py b/l10n_br_sale/models/sale_order.py index 5c09ed66b5d7..9c59620fe94c 100644 --- a/l10n_br_sale/models/sale_order.py +++ b/l10n_br_sale/models/sale_order.py @@ -106,30 +106,10 @@ def _amount_all(self): order._compute_amount() @api.model - def fields_view_get( - self, view_id=None, view_type="form", toolbar=False, submenu=False - ): - order_view = super().fields_view_get(view_id, view_type, toolbar, submenu) - - if view_type == "form": - view = self.env["ir.ui.view"] - - sub_form_view = order_view["fields"]["order_line"]["views"]["form"]["arch"] - - sub_form_node = self.env["sale.order.line"].inject_fiscal_fields( - sub_form_view - ) - - sub_arch, sub_fields = view.postprocess_and_fields( - sub_form_node, "sale.order.line" - ) - - order_view["fields"]["order_line"]["views"]["form"] = { - "fields": sub_fields, - "arch": sub_arch, - } - - return order_view + def _get_view(self, view_id=None, view_type="form", **options): + arch, view = super()._get_view(view_id, view_type, **options) + arch = self.env["sale.order.line"].inject_fiscal_fields(arch) + return arch, view @api.onchange("fiscal_operation_id") def _onchange_fiscal_operation_id(self): diff --git a/l10n_br_sale/models/sale_order_line.py b/l10n_br_sale/models/sale_order_line.py index 95f43ddf162e..2b76ef6dd48f 100644 --- a/l10n_br_sale/models/sale_order_line.py +++ b/l10n_br_sale/models/sale_order_line.py @@ -73,7 +73,10 @@ def _fiscal_operation_domain(self): # Add Fields in model sale.order.line price_gross = fields.Monetary( - compute="_compute_amount", string="Gross Amount", compute_sudo=True + compute="_compute_amount", + string="Gross Amount", + store=True, + precompute=True, ) comment_ids = fields.Many2many( @@ -89,11 +92,13 @@ def _fiscal_operation_domain(self): discount = fields.Float( compute="_compute_discounts", store=True, + precompute=True, ) discount_value = fields.Monetary( compute="_compute_discounts", store=True, + precompute=True, ) ind_final = fields.Selection(related="order_id.ind_final") @@ -110,7 +115,6 @@ def _fiscal_operation_domain(self): # Fields compute need parameter compute_sudo price_subtotal = fields.Monetary(compute_sudo=True) price_tax = fields.Monetary(compute_sudo=True) - price_total = fields.Monetary(compute_sudo=True) user_total_discount = fields.Boolean(compute="_compute_user_total_discount") user_discount_value = fields.Boolean(compute="_compute_user_discount_value") @@ -209,7 +213,6 @@ def _onchange_product_uom(self): @api.depends( "qty_delivered_method", - "qty_delivered_manual", "analytic_line_ids.so_line", "analytic_line_ids.unit_amount", "analytic_line_ids.product_uom_id", @@ -268,20 +271,21 @@ def _onchange_fiscal_tax_ids(self): def _get_product_price(self): self.ensure_one() - if ( - self.fiscal_operation_id.default_price_unit == "sale_price" + self.product_id + and self.fiscal_operation_id.default_price_unit == "sale_price" and self.order_id.pricelist_id and self.order_id.partner_id ): + price = self.with_company(self.company_id)._get_display_price() self.price_unit = self.product_id._get_tax_included_unit_price( self.company_id, self.order_id.currency_id, self.order_id.date_order, "sale", fiscal_position=self.order_id.fiscal_position_id, - product_price_unit=self._get_display_price(self.product_id), - product_currency=self.order_id.currency_id, + product_price_unit=price, + product_currency=self.currency_id, ) elif self.fiscal_operation_id.default_price_unit == "cost_price": self.price_unit = self.product_id.standard_price diff --git a/l10n_br_sale/tests/test_l10n_br_sale.py b/l10n_br_sale/tests/test_l10n_br_sale.py index c22f03fb785a..6f0bec5ccc58 100644 --- a/l10n_br_sale/tests/test_l10n_br_sale.py +++ b/l10n_br_sale/tests/test_l10n_br_sale.py @@ -149,8 +149,6 @@ def _change_user_company(self, company): self.env.user.company_id = company def _run_sale_order_onchanges(self, sale_order): - sale_order.onchange_partner_id() - sale_order.onchange_partner_shipping_id() sale_order._onchange_fiscal_operation_id() def _run_sale_line_onchanges(self, sale_line): @@ -238,7 +236,6 @@ def _invoice_sale_order(self, sale_order): ) for line in invoice.invoice_line_ids: - line._onchange_price_subtotal() self.assertTrue( line.fiscal_operation_line_id, "Error to included Operation Line from Sale Order Line.", diff --git a/l10n_br_sale/tests/test_l10n_br_sale_discount.py b/l10n_br_sale/tests/test_l10n_br_sale_discount.py index 3d843fd7ca50..ca581ba2a71e 100644 --- a/l10n_br_sale/tests/test_l10n_br_sale_discount.py +++ b/l10n_br_sale/tests/test_l10n_br_sale_discount.py @@ -16,7 +16,9 @@ def setUpClass(cls): cls.group_discount_per_value_id = cls.env.ref( "l10n_br_sale.group_discount_per_value" ).id - + cls.group_discount_per_so_line = cls.env.ref( + "product.group_discount_per_so_line" + ).id sale_manager_user = cls.env.ref("sales_team.group_sale_manager") fiscal_user = cls.env.ref("l10n_br_fiscal.group_user") user_groups = [sale_manager_user.id, fiscal_user.id] @@ -71,6 +73,7 @@ def setUpClass(cls): def test_l10n_br_sale_discount_value(self): self.user.groups_id = [(4, self.group_discount_per_value_id)] + self.user.groups_id = [(4, self.group_discount_per_so_line)] self.assertTrue(self.order_line.user_discount_value) self.assertFalse(self.order_line.user_total_discount) @@ -88,6 +91,7 @@ def test_l10n_br_sale_discount_value(self): def test_l10n_br_sale_discount_value_with_total(self): self.user.groups_id = [(4, self.group_discount_per_value_id)] self.user.groups_id = [(4, self.group_total_discount_id)] + self.user.groups_id = [(4, self.group_discount_per_so_line)] self.assertTrue(self.order_line.user_discount_value) self.assertTrue(self.order_line.user_total_discount) @@ -123,6 +127,7 @@ def test_l10n_br_sale_discount_percent(self): self.assertFalse(self.order_line.user_total_discount) self.assertTrue(self.order_line.need_change_discount_value()) + self.user.groups_id = [(4, self.group_discount_per_so_line)] order = Form(self.order) with order.order_line.edit(0) as line: line.discount = 33 @@ -134,6 +139,7 @@ def test_l10n_br_sale_discount_percent(self): def test_l10n_br_sale_discount_percent_with_total(self): self.user.groups_id = [(4, self.group_total_discount_id)] + self.user.groups_id = [(4, self.group_discount_per_so_line)] self.assertFalse(self.order_line.user_discount_value) self.assertTrue(self.order_line.user_total_discount) diff --git a/l10n_br_sale/tests/test_l10n_br_sale_pricelist.py b/l10n_br_sale/tests/test_l10n_br_sale_pricelist.py index f7d3061470b3..96b8ba17a6ea 100644 --- a/l10n_br_sale/tests/test_l10n_br_sale_pricelist.py +++ b/l10n_br_sale/tests/test_l10n_br_sale_pricelist.py @@ -43,8 +43,6 @@ def setUpClass( sale_form = Form(SaleOrder) sale_form.partner_id = cls.partner_a - sale_form.partner_invoice_id = cls.partner_a - sale_form.partner_shipping_id = cls.partner_a sale_form.fiscal_operation_id = cls.env.ref("l10n_br_fiscal.fo_venda") with sale_form.order_line.new() as line_form: diff --git a/l10n_br_sale/views/sale_view.xml b/l10n_br_sale/views/sale_view.xml index 0c4256f06a9e..d9e113fe35ad 100644 --- a/l10n_br_sale/views/sale_view.xml +++ b/l10n_br_sale/views/sale_view.xml @@ -26,7 +26,7 @@ 99 - + - + - + - {'column_invisible': [('parent.fiscal_operation_id', '!=', False)]} - + + +