Skip to content

Commit

Permalink
Merge pull request #1 from grindtildeath/14.0-fix-account_move_line_a…
Browse files Browse the repository at this point in the history
…ccounting_description

14.0 fix account move line accounting description
  • Loading branch information
ajaniszewska-dev committed Oct 29, 2021
2 parents dadd081 + f3a39ca commit 044040c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

external_name = fields.Char(string="External Name", related="product_id.name")
external_name = fields.Char(string="External Name")

@api.onchange("product_id")
def _onchange_product_id(self):
super()._onchange_product_id()
for line in self:
line.external_name = line.name
if line.product_id.accounting_description:
line.name = line.product_id.accounting_description
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,18 @@ def setUpClass(cls):

cls.account_move = cls.env["account.move"]

def test_invoice_line_with_accounting_description(self):
invoice_form_acc_desc = Form(
cls.account_move.with_context(default_move_type="out_invoice")
self.account_move.with_context(default_move_type="out_invoice")
)
invoice_form_no_acc_desc = Form(
cls.account_move.with_context(default_move_type="out_invoice")
)

invoice_form_acc_desc.partner_id = (
invoice_form_no_acc_desc.partner_id
) = cls.partner_1
invoice_form_acc_desc.partner_id = self.partner_1

with invoice_form_acc_desc.invoice_line_ids.new() as line_form:
line_form.product_id = cls.product_with_acc_desc
line_form.product_id = self.product_with_acc_desc
line_form.quantity = 1
line_form.price_unit = 2.99

cls.invoice_acc_desc = invoice_form_acc_desc.save()

with invoice_form_no_acc_desc.invoice_line_ids.new() as line_form:
line_form.product_id = cls.product_without_acc_desc
line_form.quantity = 1
line_form.price_unit = 2.99

cls.invoice_no_acc_desc = invoice_form_no_acc_desc.save()

def test_invoice_line_description(self):
self.invoice_acc_desc = invoice_form_acc_desc.save()
inv_line_with_product = self.invoice_acc_desc.invoice_line_ids.filtered(
lambda x: x.product_id
)
Expand All @@ -58,11 +44,23 @@ def test_invoice_line_description(self):
inv_line_with_product.name,
self.product_with_acc_desc.accounting_description,
)

self.assertEqual(
inv_line_with_product.product_id.name, inv_line_with_product.external_name
)

def test_invoice_line_without_accounting_description(self):
invoice_form_no_acc_desc = Form(
self.account_move.with_context(default_move_type="out_invoice")
)

invoice_form_no_acc_desc.partner_id = self.partner_1

with invoice_form_no_acc_desc.invoice_line_ids.new() as line_form:
line_form.product_id = self.product_without_acc_desc
line_form.quantity = 1
line_form.price_unit = 2.99

self.invoice_no_acc_desc = invoice_form_no_acc_desc.save()
inv_line_with_product = self.invoice_no_acc_desc.invoice_line_ids.filtered(
lambda x: x.product_id
)
Expand Down
12 changes: 12 additions & 0 deletions account_move_line_accounting_description/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
<xpath expr="//field[@name='invoice_line_ids']//form" position="inside">
<field name="external_name" />
</xpath>
<!--
WARNING: We need to display the field as invisible here although it
is already defined on invoice_line_ids tree above. Having it
defined only there would only set the external_name key with its
value inside the invoice_line_ids key of the values dictionary
that is passed to create function. However, this invoice_line_ids
key is popped in account.move._move_autocomplete_invoice_lines_create
function to keep only the line_ids to create the account.move and
avoid duplicated account.move.line records. -->
<xpath expr="//field[@name='line_ids']//tree" position="inside">
<field name="external_name" invisible="1" />
</xpath>
</field>
</record>
</odoo>

0 comments on commit 044040c

Please sign in to comment.