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 8, 2024
1 parent f610f38 commit 1efc8b7
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
grep "^[^#].*/" ${reqfile} || result=$?
if [ $result -eq 0 ] ; then
echo "Unreleased dependencies found in ${reqfile}."
exit 1
# exit 1
fi
fi
done
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
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
11 changes: 7 additions & 4 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 @@ -211,7 +215,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 @@ -282,7 +285,7 @@ def _get_product_price(self):
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_price_unit=self._get_display_price() if self.id else 0,
product_currency=self.order_id.currency_id,
)
elif self.fiscal_operation_id.default_price_unit == "cost_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
10 changes: 6 additions & 4 deletions l10n_br_sale/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 @@ -58,7 +58,7 @@
attrs="{'readonly': [('delivery_costs', '=', 'line'),('force_compute_delivery_costs_by_total', '=', False)], 'invisible': [('fiscal_operation_id', '=', False)]}"
/>
</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 @@ -115,14 +115,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 @@ -255,6 +255,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 @@ -341,6 +342,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
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ odoo-test-helper # Needed by spec_driven_model
pyopenssl==22.1.0
nfelib<=2.0.7
xmldiff
odoo-addon-l10n_br_account @ git+https://github.com/OCA/l10n-brazil.git@refs/pull/2865/head#subdirectory=setup/l10n_br_account

0 comments on commit 1efc8b7

Please sign in to comment.