changeset 0e81e4cf1d32 in modules/sale_amendment:default
details:
https://hg.tryton.org/modules/sale_amendment?cmd=changeset;node=0e81e4cf1d32
description:
Support amend line without product
issue9811
review331611002
diffstat:
CHANGELOG | 2 ++
sale.py | 23 +++++++++++++++--------
tests/scenario_sale_amendment.rst | 27 ++++++++++++++++++++++-----
3 files changed, 39 insertions(+), 13 deletions(-)
diffs (161 lines):
diff -r b715129b32da -r 0e81e4cf1d32 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 b715129b32da -r 0e81e4cf1d32 sale.py
--- a/sale.py Sat Dec 19 17:08:46 2020 +0100
+++ b/sale.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
@@ -267,12 +267,13 @@
If(Eval('state') == 'draft',
('salable', '=', 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'])
quantity = fields.Float(
@@ -287,14 +288,16 @@
unit = fields.Many2One(
'product.uom', "Unit", ondelete='RESTRICT',
domain=[
- ('category', '=', Eval('product_uom_category')),
+ If(Eval('product_uom_category'),
+ ('category', '=', Eval('product_uom_category')),
+ ()),
],
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={
@@ -406,7 +409,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, sale):
assert self.sale == sale
@@ -420,7 +426,8 @@
def _apply_taxes(self, sale, sale_line):
for line in sale.lines:
- line.taxes = line.compute_taxes(sale.party)
+ if line.product:
+ line.taxes = line.compute_taxes(sale.party)
def _apply_payment_term(self, sale, sale_line):
sale.payment_term = self.payment_term
diff -r b715129b32da -r 0e81e4cf1d32 tests/scenario_sale_amendment.rst
--- a/tests/scenario_sale_amendment.rst Sat Dec 19 17:08:46 2020 +0100
+++ b/tests/scenario_sale_amendment.rst Mon Jan 18 23:26:35 2021 +0100
@@ -78,6 +78,9 @@
>>> sale_line = sale.lines.new()
>>> sale_line.product = product1
>>> sale_line.quantity = 5.0
+ >>> sale_line = sale.lines.new()
+ >>> sale_line.quantity = 1
+ >>> sale_line.unit_price = Decimal('5.0000')
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
@@ -85,7 +88,7 @@
>>> sale.revision
0
>>> sale.total_amount
- Decimal('50.00')
+ Decimal('55.00')
>>> len(sale.shipments), len(sale.invoices)
(1, 1)
@@ -107,7 +110,7 @@
True
>>> line = amendment.lines.new()
>>> line.action = 'line'
- >>> line.line, = sale.lines
+ >>> line.line = sale.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 = sale.lines[1]
+ >>> line.product
+ >>> line.quantity = 2
>>> amendment.save()
Validate amendment::
@@ -127,15 +135,18 @@
1
>>> sale.party == customer2
True
- >>> line, = sale.lines
+ >>> line = sale.lines[0]
>>> line.product == product2
True
>>> line.quantity
4.0
>>> line.unit_price
Decimal('9.0000')
+ >>> line = sale.lines[1]
+ >>> line.quantity
+ 2.0
>>> sale.total_amount
- Decimal('36.00')
+ Decimal('46.00')
>>> shipment, = sale.shipments
>>> move, = shipment.outgoing_moves
@@ -145,10 +156,16 @@
4.0
>>> invoice, = sale.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')