Issue 11230

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

Created on 2022-02-09.12:24:47 by resteve, last changed 3 weeks ago by roundup-bot.

Messages

New changeset bba0c5062c7d by Cédric Krier in branch '6.4':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/web_shop/rev/bba0c5062c7d

New changeset d58df28746b4 by Cédric Krier in branch '6.2':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/web_shop/rev/d58df28746b4
New changeset 35b0bb152ef0 by Cédric Krier in branch '6.4':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/stock_consignment/rev/35b0bb152ef0

New changeset 855d89552bd6 by Cédric Krier in branch '6.2':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/stock_consignment/rev/855d89552bd6
New changeset d50f5ad354e8 by Cédric Krier in branch '6.4':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale/rev/d50f5ad354e8

New changeset c7e8c1dfef72 by Cédric Krier in branch '6.2':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale/rev/c7e8c1dfef72
New changeset 27a1a34ce6ec by Cédric Krier in branch '6.4':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/purchase/rev/27a1a34ce6ec

New changeset ef7519ebd9f0 by Cédric Krier in branch '6.2':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/purchase/rev/ef7519ebd9f0
New changeset 8fffa57bd1f8 by Cédric Krier in branch '6.4':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/account_invoice/rev/8fffa57bd1f8

New changeset 32b96d770e06 by Cédric Krier in branch '6.2':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/account_invoice/rev/32b96d770e06
New changeset d1ff45c2ad73 by Cédric Krier in branch 'default':
Ensure ModelList contains only unique records
https://hg.tryton.org/tryton-env/rev/d1ff45c2ad73

New changeset 00eddfa2d25f by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/tryton-env/rev/00eddfa2d25f

New changeset f17f1736dfe0 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/tryton-env/rev/f17f1736dfe0
New changeset 7cedd42a20a6 by Cédric Krier in branch 'default':
Ensure ModelList contains only unique records
https://hg.tryton.org/proteus/rev/7cedd42a20a6
New changeset b31d8703761f by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/web_shop/rev/b31d8703761f

New changeset 88341b1ac454 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/web_shop/rev/88341b1ac454
New changeset 4b2d18f8cd61 by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/stock_consignment/rev/4b2d18f8cd61

New changeset 2f7565adb5d1 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/stock_consignment/rev/2f7565adb5d1
New changeset e818d2e49488 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale_subscription/rev/e818d2e49488
New changeset d23014d401c0 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale_shipment_cost/rev/d23014d401c0
New changeset 453100758df4 by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale/rev/453100758df4

New changeset 641d0de67c3d by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/sale/rev/641d0de67c3d
New changeset 60fe20c8a431 by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/purchase/rev/60fe20c8a431

New changeset cc5b530e667e by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/purchase/rev/cc5b530e667e
New changeset 7dc8f95b54d1 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/project_invoice/rev/7dc8f95b54d1
New changeset 33d9a972aec9 by Cédric Krier in branch 'default':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/account_invoice/rev/33d9a972aec9

New changeset 6c15b6bb98e4 by Cédric Krier in branch '6.0':
Ensure unique taxes when applying tax rule
https://hg.tryton.org/modules/account_invoice/rev/6c15b6bb98e4
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2022-06-29.00:31:27

Here is review415271003 for the 6.0 branch.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2022-06-16.10:01:19

Here is review419361003 which ensures all tax rule applications result in unique taxes.

I think both reviews must be backported as it may result in wrong tax computation.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2022-06-16.09:50:33

Here is review435351003 that ensures the same behavior in proteus.
But indeed it is not enough (even with issue10841) because as msg73970 shows it can happen when calling the on_change methods inside the ORM. Even if I do not think there is a valid case where tax rules should result in changing multiple taxes into the same tax, we should prevent the code to fail because of the unique constraint.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2022-06-16.09:27:33

With issue10841 there is no need to make target_ids unique and it will anyway not solve the problem as only a unique constraint has the transactional ability to do it.
Any way proteus should behave like the other clients.

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-07-17 19:49:45roundup-botsetmessages: + msg77393
2022-07-17 19:49:36roundup-botsetmessages: + msg77390
2022-07-17 19:49:13roundup-botsetmessages: + msg77387
2022-07-17 19:48:57roundup-botsetmessages: + msg77385
2022-07-17 19:48:21roundup-botsetmessages: + msg77378
2022-07-17 00:04:34roundup-botsetmessages: + msg77363
2022-07-17 00:04:28roundup-botsetmessages: + msg77362
2022-07-17 00:04:17roundup-botsetmessages: + msg77361
2022-07-17 00:04:03roundup-botsetmessages: + msg77359
2022-07-17 00:03:57roundup-botsetmessages: + msg77357

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