Issue 11230

Title
Many2Many values are not always unique
Priority
bug
Status
chatting
Nosy list
ced, pokoli, resteve, reviewbot
Assigned to
Keywords
review

Created on 2022-02-09.12:24:47 by resteve, last changed 3 months ago by pokoli.

Messages

Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2022-02-09.18:48:37

I guess your are not using 6.2 series as this should raise and error message since issue10841

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2022-02-09.14:16:36

For me the problem is that the ORM create multiple record of the same target in Many2Many when there is code to prevent that. Indeed I think it is because target_ids should be made unique.
Also proteus should behave like the other client and keep only unique instance of record in Many2Many.

Author: [hidden] (resteve)
Date: 2022-02-09.12:37:45

At the moment I published review395481002 related to invoices. Missing sales, etc...

Author: [hidden] (resteve)
Date: 2022-02-09.12:24:47

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 18:48:38pokolisetmessages: + msg73982
nosy: + pokoli
2022-02-09 14:16:37cedsetcomponent: + trytond, proteus, - account_invoice, purchase, sale
messages: + msg73975
nosy: + ced
title: Not expand tax when ID tax has in taxes (account invoice :: on_change_product) -> Many2Many values are not always unique
2022-02-09 12:41:17reviewbotsetmessages: + msg73972
nosy: + reviewbot
2022-02-09 12:37:45restevesetkeyword: + review
messages: + msg73971
reviews: 395481002
2022-02-09 12:24:47restevecreate

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