changeset ab1d1564f619 in modules/purchase_amendment:default
details:
https://hg.tryton.org/modules/purchase_amendment?cmd=changeset;node=ab1d1564f619
description:
Support amend line without product
issue9811
review331611002
diffstat:
CHANGELOG | 2 ++
purchase.py | 19 ++++++++++++-------
tests/scenario_purchase_amendment.rst | 27 ++++++++++++++++++++++-----
3 files changed, 36 insertions(+), 12 deletions(-)
diffs (153 lines):
diff -r 14ac3383cef3 -r ab1d1564f619 CHANGELOG
--- a/CHANGELOG Sat Dec 19 17:08:46 2020 +0100
+++ b/CHANGELOG Mon Jan 18 23:26:35 2021 +0100
@@ -1,3 +1,5 @@
+* Support amend line without product
+
Version 5.8.0 - 2020-11-02
* Bug fixes (see mercurial logs for details)
* Remove support for Python 3.5
diff -r 14ac3383cef3 -r ab1d1564f619 purchase.py
--- a/purchase.py Sat Dec 19 17:08:46 2020 +0100
+++ b/purchase.py Mon Jan 18 23:26:35 2021 +0100
@@ -4,7 +4,7 @@
from trytond.i18n import gettext
from trytond.model import ModelSQL, ModelView, Workflow, fields
from trytond.pool import Pool, PoolMeta
-from trytond.pyson import Eval, If
+from trytond.pyson import Eval, If, Bool
from trytond.modules.product import price_digits
@@ -233,12 +233,13 @@
If(Eval('state') == 'draft',
('purchasable', '=', True),
()),
- ('default_uom_category', '=', Eval('product_uom_category')),
+ If(Eval('product_uom_category'),
+ ('default_uom_category', '=', Eval('product_uom_category')),
+ ()),
],
states={
'readonly': Eval('state') != 'draft',
'invisible': Eval('action') != 'line',
- 'required': Eval('action') == 'line',
},
depends=['action', 'state', 'product_uom_category'])
product_supplier = fields.Many2One(
@@ -277,9 +278,9 @@
states={
'readonly': Eval('state') != 'draft',
'invisible': Eval('action') != 'line',
- 'required': Eval('action') == 'line',
+ 'required': Bool(Eval('product')),
},
- depends=['state', 'product_uom_category', 'action'])
+ depends=['state', 'product_uom_category', 'action', 'product'])
unit_price = fields.Numeric(
"Unit Price", digits=price_digits,
states={
@@ -376,7 +377,10 @@
@fields.depends('line')
def on_change_with_product_uom_category(self, name=None):
if self.line:
- return self.line.product_uom_category.id
+ if self.line.product_uom_category:
+ return self.line.product_uom_category.id
+ elif self.line.unit:
+ return self.line.unit.category.id
def apply(self, purchase):
assert self.purchase == purchase
@@ -390,7 +394,8 @@
def _apply_taxes(self, purchase, purchase_line):
for line in purchase.lines:
- line.taxes = line.compute_taxes(purchase.party)
+ if line.product:
+ line.taxes = line.compute_taxes(purchase.party)
def _apply_payment_term(self, purchase, purchase_line):
purchase.payment_term = self.payment_term
diff -r 14ac3383cef3 -r ab1d1564f619 tests/scenario_purchase_amendment.rst
--- a/tests/scenario_purchase_amendment.rst Sat Dec 19 17:08:46 2020 +0100
+++ b/tests/scenario_purchase_amendment.rst Mon Jan 18 23:26:35 2021 +0100
@@ -78,6 +78,9 @@
>>> purchase_line.product = product1
>>> purchase_line.quantity = 5.0
>>> purchase_line.unit_price = Decimal('10.0000')
+ >>> purchase_line = purchase.lines.new()
+ >>> purchase_line.quantity = 1
+ >>> purchase_line.unit_price = Decimal('5.0000')
>>> purchase.click('quote')
>>> purchase.click('confirm')
>>> purchase.state
@@ -85,7 +88,7 @@
>>> purchase.revision
0
>>> purchase.total_amount
- Decimal('50.00')
+ Decimal('55.00')
>>> len(purchase.moves), len(purchase.invoices)
(1, 1)
@@ -107,7 +110,7 @@
True
>>> line = amendment.lines.new()
>>> line.action = 'line'
- >>> line.line, = purchase.lines
+ >>> line.line = purchase.lines[0]
>>> line.product == product1
True
>>> line.product = product2
@@ -117,6 +120,11 @@
>>> line.unit_price
Decimal('10.0000')
>>> line.unit_price = Decimal('9.0000')
+ >>> line = amendment.lines.new()
+ >>> line.action = 'line'
+ >>> line.line = purchase.lines[1]
+ >>> line.product
+ >>> line.quantity = 2
>>> amendment.save()
Validate amendment::
@@ -127,15 +135,18 @@
1
>>> purchase.party == supplier2
True
- >>> line, = purchase.lines
+ >>> line = purchase.lines[0]
>>> line.product == product2
True
>>> line.quantity
4.0
>>> line.unit_price
Decimal('9.0000')
+ >>> line = purchase.lines[1]
+ >>> line.quantity
+ 2.0
>>> purchase.total_amount
- Decimal('36.00')
+ Decimal('46.00')
>>> move, = purchase.moves
>>> move.product == product2
@@ -144,10 +155,16 @@
4.0
>>> invoice, = purchase.invoices
- >>> line, = invoice.lines
+ >>> line = invoice.lines[0]
>>> line.product == product2
True
>>> line.quantity
4.0
>>> line.unit_price
Decimal('9.0000')
+ >>> line = invoice.lines[1]
+ >>> line.product
+ >>> line.quantity
+ 2.0
+ >>> line.unit_price
+ Decimal('5.0000')