Skip to content

Commit

Permalink
MIG] l10n_br_sale: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Aug 24, 2024
1 parent 6ea0fa7 commit f0e5742
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 44 deletions.
4 changes: 2 additions & 2 deletions l10n_br_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +33,5 @@
"auto_install": True,
"post_init_hook": "post_init_hook",
"development_status": "Beta",
"maintainers": ["renatonlima"],
"maintainers": ["renatonlima", "rvalyi"],
}
28 changes: 4 additions & 24 deletions l10n_br_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 11 additions & 7 deletions l10n_br_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions l10n_br_sale/tests/test_l10n_br_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.",
Expand Down
8 changes: 7 additions & 1 deletion l10n_br_sale/tests/test_l10n_br_sale_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions l10n_br_sale/tests/test_l10n_br_sale_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions l10n_br_sale/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<field name="inherit_id" ref="sale.view_order_form" />
<field name="priority">99</field>
<field name="arch" type="xml">
<field name="tax_totals_json" position="before">
<field name="tax_totals" position="before">
<field
name="amount_untaxed"
widget='monetary'
Expand Down Expand Up @@ -64,15 +64,15 @@
attrs="{'readonly': [('delivery_costs', '=', 'line'),('force_compute_delivery_costs_by_total', '=', False)], 'invisible': [('fiscal_operation_id', '=', False)]}"
/>
</field>
<field name="amount_tax_json" position="before">
<field name="tax_totals" position="before">
<field
name="amount_tax_withholding"
widget='monetary'
options="{'currency_field': 'currency_id'}"
attrs="{'invisible': [('fiscal_operation_id', '=', False), ('amount_tax_withholding', '=', 0) ]}"
/>
</field>
<field name="tax_totals_json" position="after">
<field name="tax_totals" position="after">
<field
name="amount_financial_total"
widget='monetary'
Expand Down Expand Up @@ -130,14 +130,14 @@
<xpath expr="//field[@name='order_line']/tree" position="attributes">
<attribute name="editable" />
</xpath>
<xpath
<!-- FIXME xpath
expr="//field[@name='order_line']/tree/field[@name='analytic_tag_ids']"
position="attributes"
>
<attribute
name="attrs"
>{'column_invisible': [('parent.fiscal_operation_id', '!=', False)]}</attribute>
</xpath>
</xpath-->
<xpath
expr="//field[@name='order_line']//form//field[@name='product_id']"
position="attributes"
Expand Down Expand Up @@ -270,6 +270,7 @@
name="fiscal_quantity"
class="oe_inline"
/>
<field name="uot_id" invisible="1" force_save="1" />
<field
name="uot_id"
force_save="1"
Expand Down Expand Up @@ -356,6 +357,7 @@
expr="//field[@name='order_line']/form//label[@for='discount']"
position="before"
>
<field name="discount_fixed" invisible="1" />
<field
name="discount_fixed"
groups="l10n_br_sale.group_total_discount"
Expand Down

0 comments on commit f0e5742

Please sign in to comment.