Message 73970

Author
resteve
Date
2022-02-09.12:24:47
Message id
73970

Content

Scenario:

  1. Create taxes: Tax1 and Tax2
  2. Create a product: Product1 Add Tax1 and Tax2 in account category
  3. Create a account tax rule: "Rule1". Add a new line:
    3.1. origin_tax: None
    3.2. tax: Tax1
  4. Create a party: Party1. Add customer_tax_rule related to "Rule1"
  5. Create an invoice: party is Party1 and create a new product: product1

When do on_change_product, len(taxes) == 3 but client only show two taxes: tax1 and tax2

Now, open a trytond-console, and do same operation.

>>> transaction.set_user(1)
>>> User = pool.get('res.user')
>>> context = User.get_preferences(context_only=True)
>>> transaction.set_context(context)
>>> Invoice = pool.get('account.invoice')
>>> invoice = Invoice(1)
>>> InvoiceLine = pool.get('account.invoice.line')
>>> Product = pool.get('product.product')
>>> product = Product(1)
>>> invoice_line = InvoiceLine()
>>> invoice_line.invoice = invoice
>>> invoice_line.product = product
>>> invoice_line.on_change_product()
> /home/raimon/projectes/nandev/049296/trytond/trytond/modules/account_invoice/invoice.py(2197)on_change_product()
-> self.taxes = taxes
(Pdb) taxes
[1, 30, 30]
(Pdb) c
Pool().get('account.invoice.line')(**{'taxes': [1, 30, 30], 'unit': 1, 'party': None, 'unit_digits': 0, 'company': 1, 'product': 1, 'invoice_type': None, 'account': 1588, 'invoice': 1})
>>> from decimal import Decimal
>>> invoice_line.quantity = Decimal(1)
>>> invoice_line.unit_price = Decimal(1)
>>> invoice_line.save()
>>> invoice_line.taxes
(Pool().get('account.tax')(1), Pool().get('account.tax')(30), Pool().get('account.tax')(30))
>>> Invoice.update_taxes([invoice])
>>> invoice.taxes
(Pool().get('account.invoice.tax')(1), Pool().get('account.invoice.tax')(2))
>>> invoice.untaxed_amount
Decimal('1.00')
>>> [t.base for t in invoice.taxes]
[Decimal('1.00'), Decimal('2.00')]
>>> [(t.tax, t.base) for t in invoice.taxes]
[(Pool().get('account.tax')(1), Decimal('1.00')), (Pool().get('account.tax')(30), Decimal('2.00'))]

SQL:

# select id, line, tax from account_invoice_line_account_tax;
 id | line | tax 
----+------+-----
  7 |    3 |   1
  8 |    3 |  30
  9 |    3 |  30

Bug:
- Invoice line has three taxes: tax1, tax2 and tax2
- update_taxes(), the base from tax1 is 2.00 and not 1.00 (from total taxes in invoice line)

Reason:
New tax_ids are added in current list (extend). We need to set() unique taxes.

https://github.com/tryton/account_invoice/blob/6cb358db41d9c300934d8cfffa15bd04354509be/invoice.py#L2260

History
Date User Action Args
2022-02-09 12:24:47restevesetmessageid: <1644405887.6049402.ZGZG6IEI3GGGQ5WR.issue11230@tryton.org>
2022-02-09 12:24:47restevelinkissue11230 messages
2022-02-09 12:24:47restevecreate

Showing 10 items. Show all history (warning: this could be VERY long)