Skip to content

Commit

Permalink
[MIG] account_invoice_triple_discount: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiadavid committed Jan 12, 2023
1 parent 008a8a3 commit 9f5ba13
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 86 deletions.
2 changes: 1 addition & 1 deletion account_invoice_triple_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Invoice Triple Discount",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"author": "QubiQ, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ msgstr ""
msgid "<span>Disc.3 %</span>"
msgstr ""

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr ""

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr ""

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_move_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Desc.2%"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Desc.3%"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 3.1.1\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "2. Rabatt (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "3. Rabatt (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Remise 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Remise 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/hr.po
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Popust 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Popust 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/hr_HR.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Popust 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Popust 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Sconto 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Sconto 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: Weblate 3.8\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Desconto 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Desconto 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_triple_discount/i18n/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ msgstr ""
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.2%"
msgstr "Скидка 2 (%)"

#. module: account_invoice_triple_discount
#: model_terms:ir.ui.view,arch_db:account_invoice_triple_discount.invoice_triple_discount_form_view
msgid "Disc.3%"
msgstr "Скидка 3 (%)"

#. module: account_invoice_triple_discount
#: model:ir.model.fields,field_description:account_invoice_triple_discount.field_account_invoice_line__discount2
msgid "Discount 2 (%)"
Expand Down
1 change: 0 additions & 1 deletion account_invoice_triple_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import account_move
from . import account_move_line
44 changes: 0 additions & 44 deletions account_invoice_triple_discount/models/account_move.py

This file was deleted.

75 changes: 59 additions & 16 deletions account_invoice_triple_discount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,73 @@ def create(self, values_list):
record.write(old_values[index])
return records

@api.onchange(
@api.depends(
"quantity",
"discount",
"price_unit",
"tax_ids",
"quantity",
"currency_id",
"discount2",
"discount3",
)
def _onchange_price_subtotal(self):
return super(AccountMoveLine, self)._onchange_price_subtotal()
def _compute_totals(self):
"""
As the totals are recalculated based on a single discount, we need to
simulate a multiple discount by changing the discount value. Values are
restored after the original process is done
"""
old_values_by_line_id = {}
digits = self._fields["discount"]._digits
self._fields["discount"]._digits = (16, 16)
for line in self:
aggregated_discount = line._compute_aggregated_discount(line.discount)
old_values_by_line_id[line.id] = {"discount": line.discount}
line.update({"discount": aggregated_discount})
res = super(AccountMoveLine, self)._compute_totals()
self._fields["discount"]._digits = digits
for line in self:
if line.id not in old_values_by_line_id:
continue
line.update(old_values_by_line_id[line.id])
return res

def _get_price_total_and_subtotal(self, **kwargs):
self.ensure_one()
kwargs["discount"] = self._compute_aggregated_discount(
kwargs.get("discount") or self.discount
)
return super(AccountMoveLine, self)._get_price_total_and_subtotal(**kwargs)
@api.depends(
"tax_ids",
"currency_id",
"partner_id",
"analytic_distribution",
"balance",
"partner_id",
"move_id.partner_id",
"price_unit",
"discount2",
"discount3",
)
def _compute_all_tax(self):
"""
As the taxes are recalculated based on a single discount, we need to
simulate a multiple discount by changing discount value. Values are
restored after the original process is done
"""
digits = self._fields["discount"]._digits
self._fields["discount"]._digits = (16, 16)
old_values_by_line_id = {}
for line in self:
aggregated_discount = line._compute_aggregated_discount(line.discount)
old_values_by_line_id[line.id] = {"discount": line.discount}
line.update({"discount": aggregated_discount})
res = super(AccountMoveLine, self)._compute_all_tax()
self._fields["discount"]._digits = digits
for line in self:
if line.id not in old_values_by_line_id:
continue
line.update(old_values_by_line_id[line.id])
return res

def _get_fields_onchange_balance(self, **kwargs):
self.ensure_one()
kwargs["discount"] = self._compute_aggregated_discount(
kwargs.get("discount") or self.discount
)
return super(AccountMoveLine, self)._get_fields_onchange_balance(**kwargs)
def _convert_to_tax_base_line_dict(self):
res = super(AccountMoveLine, self)._convert_to_tax_base_line_dict()
res["discount"] = self._compute_aggregated_discount(res["discount"])
return res

def _compute_aggregated_discount(self, base_discount):
self.ensure_one()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class TestInvoiceTripleDiscount(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestInvoiceTripleDiscount, cls).setUpClass()
cls.env.user.groups_id += cls.env.ref("product.group_discount_per_so_line")
cls.Account = cls.env["account.account"]
cls.AccountMove = cls.env["account.move"]
cls.AccountTax = cls.env["account.tax"]
cls.AccountType = cls.env["account.account.type"]
cls.Partner = cls.env["res.partner"]
cls.Journal = cls.env["account.journal"]

Expand All @@ -26,14 +26,11 @@ def setUpClass(cls):
"country_id": cls.env.ref("base.us").id,
}
)
cls.account_type = cls.AccountType.create(
{"name": "Test", "type": "receivable", "internal_group": "income"}
)
cls.account = cls.Account.create(
{
"name": "Test account",
"code": "TEST",
"user_type_id": cls.account_type.id,
"account_type": "asset_receivable",
"reconcile": True,
}
)
Expand Down
23 changes: 4 additions & 19 deletions account_invoice_triple_discount/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,15 @@
expr="//field[@name='invoice_line_ids']//tree//field[@name='discount']"
position="after"
>
<field
name="discount2"
groups="product.group_discount_per_so_line"
optional="show"
/>
<field
name="discount3"
groups="product.group_discount_per_so_line"
optional="show"
/>
<field name="discount2" optional="hide" string="Disc.2%" />
<field name="discount3" optional="hide" string="Disc.3%" />
</xpath>
<xpath
expr="//field[@name='invoice_line_ids']//form//field[@name='discount']"
position="after"
>
<field name="discount2" groups="product.group_discount_per_so_line" />
<field name="discount3" groups="product.group_discount_per_so_line" />
</xpath>
<xpath
expr="//field[@name='line_ids']//tree//field[@name='discount']"
position="after"
>
<field name="discount2" invisible="1" />
<field name="discount3" invisible="1" />
<field name="discount2" string="Disc.2%" />
<field name="discount3" string="Disc.3%" />
</xpath>
</field>
</record>
Expand Down

0 comments on commit 9f5ba13

Please sign in to comment.