changeset d32be8f2f739 in modules/sale_shipment_cost:default
details:
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset&node=d32be8f2f739
description:
Move carrier and cost from sale_shipment_cost to stock_shipment_cost
issue10375
review358031002
diffstat:
doc/index.rst | 6 -
setup.py | 1 -
stock.py | 104 +++++----------------------
tests/scenario_sale_shipment_cost_stock.rst | 1 -
tryton.cfg | 2 +-
view/shipment_out_form.xml | 23 +----
6 files changed, 28 insertions(+), 109 deletions(-)
diffs (265 lines):
diff -r 12fd01814411 -r d32be8f2f739 doc/index.rst
--- a/doc/index.rst Mon May 03 16:05:31 2021 +0200
+++ b/doc/index.rst Wed May 19 12:44:43 2021 +0200
@@ -15,9 +15,3 @@
At the quotation if a carrier is selected a new line is appended with the
shipment cost but the added line can be modified when going back to draft.
-
-Three new fields are added to *Customer Shipment*:
-
-- *Carrier*: The carrier used for the shipment.
-- *Cost*: The cost of the shipment.
-- *Cost Currency*: The currency of the cost.
diff -r 12fd01814411 -r d32be8f2f739 setup.py
--- a/setup.py Mon May 03 16:05:31 2021 +0200
+++ b/setup.py Wed May 19 12:44:43 2021 +0200
@@ -65,7 +65,6 @@
tests_require = [
get_require_version('proteus'),
- get_require_version('trytond_stock_shipment_cost'),
]
for dep in ['account', 'party', 'stock', 'sale_promotion']:
tests_require.append(get_require_version('trytond_%s' % dep))
diff -r 12fd01814411 -r d32be8f2f739 stock.py
--- a/stock.py Mon May 03 16:05:31 2021 +0200
+++ b/stock.py Wed May 19 12:44:43 2021 +0200
@@ -12,66 +12,34 @@
class ShipmentOut(metaclass=PoolMeta):
__name__ = 'stock.shipment.out'
- carrier = fields.Many2One('carrier', 'Carrier', states={
- 'readonly': ~Eval('state').in_(['draft', 'waiting', 'assigned',
- 'picked', 'packed']),
- },
- depends=['state'])
- cost_used = fields.Function(fields.Numeric(
- "Cost", digits=price_digits,
- states={
- 'invisible': ~Eval('carrier') | Eval('cost_edit', False),
- },
- depends=['carrier', 'cost_edit']),
- 'on_change_with_cost_used')
- cost = fields.Numeric(
- "Cost", digits=price_digits,
- states={
- 'invisible': ~Eval('carrier') | ~Eval('cost_edit', False),
- 'readonly': ~Eval('state').in_(
- ['draft', 'waiting', 'assigned', 'picked', 'packed']),
- },
- depends=['carrier', 'state'])
cost_sale_currency_used = fields.Function(fields.Many2One(
'currency.currency', "Cost Sale Currency",
states={
- 'invisible': ~Eval('carrier') | Eval('cost_edit', False),
+ 'invisible': Eval('cost_edit', False),
},
- depends=['carrier', 'cost_edit']),
+ depends=['cost_edit']),
'on_change_with_cost_sale_currency_used')
cost_sale_currency = fields.Many2One(
'currency.currency', "Cost Sale Currency",
states={
- 'invisible': ~Eval('carrier') | ~Eval('cost_edit', False),
+ 'invisible': ~Eval('cost_edit', False),
'required': Bool(Eval('cost_sale')),
- 'readonly': ~Eval('state').in_(
- ['draft', 'waiting', 'assigned', 'picked', 'packed']),
- }, depends=['carrier', 'cost_sale', 'state'])
+ 'readonly': Eval('state').in_(['done', 'cancelled']),
+ }, depends=['cost_sale', 'state'])
cost_sale_used = fields.Function(fields.Numeric(
"Cost Sale", digits=price_digits,
states={
- 'invisible': ~Eval('carrier') | Eval('cost_edit', False),
+ 'invisible': Eval('cost_edit', False),
},
- depends=['carrier', 'cost_edit']),
+ depends=['cost_edit']),
'on_change_with_cost_sale_used')
cost_sale = fields.Numeric(
"Cost Sale", digits=price_digits,
states={
- 'invisible': ~Eval('carrier') | ~Eval('cost_edit', False),
- 'readonly': ~Eval('state').in_(
- ['draft', 'waiting', 'assigned', 'picked', 'packed']),
- }, depends=['carrier', 'state'])
-
- cost_edit = fields.Boolean(
- "Edit Cost",
- states={
- 'invisible': ~Eval('carrier'),
- 'readonly': ~Eval('state').in_(
- ['draft', 'waiting', 'assigned', 'picked', 'packed']),
- },
- depends=['carrier', 'state'],
- help="Check to edit the cost.")
+ 'invisible': ~Eval('cost_edit', False),
+ 'readonly': ~Eval('state').in_(['done', 'cancelled']),
+ }, depends=['state'])
cost_invoice_line = fields.Many2One('account.invoice.line',
'Cost Invoice Line', readonly=True)
@@ -88,42 +56,21 @@
table_h.column_rename('cost_currency', 'cost_sale_currency')
super().__register__(module)
- def _get_carrier_context(self):
- return {}
-
- def get_carrier_context(self):
- return self._get_carrier_context()
-
@fields.depends('carrier', 'company', methods=['_get_carrier_context'])
def _compute_costs(self):
- pool = Pool()
- Currency = pool.get('currency.currency')
- costs = {
- 'cost': None,
- 'cost_sale': None,
- 'cost_sale_currency': None,
- }
+ costs = super()._compute_costs()
+ costs.update({
+ 'cost_sale': None,
+ 'cost_sale_currency': None,
+ })
if self.carrier:
with Transaction().set_context(self._get_carrier_context()):
- cost, currency_id = self.carrier.get_purchase_price()
cost_sale, sale_currency_id = self.carrier.get_sale_price()
- if cost is not None:
- cost = Currency.compute(
- Currency(currency_id), cost, self.company.currency,
- round=False)
- costs['cost'] = round_price(cost)
if cost_sale is not None:
costs['cost_sale'] = round_price(cost_sale)
costs['cost_sale_currency'] = sale_currency_id
return costs
- @fields.depends('state', 'cost', 'cost_edit', methods=['_compute_costs'])
- def on_change_with_cost_used(self, name=None):
- if not self.cost_edit and self.state not in {'cancelled', 'done'}:
- return self._compute_costs()['cost']
- else:
- return self.cost
-
@fields.depends(
'state', 'cost_sale', 'cost_edit', methods=['_compute_costs'])
def on_change_with_cost_sale_used(self, name=None):
@@ -140,11 +87,10 @@
elif self.cost_sale_currency:
return self.cost_sale_currency.id
- @fields.depends(
- 'cost_edit', 'cost_used', 'cost_sale_used', 'cost_sale_currency_used')
+ @fields.depends('cost_edit', 'cost_sale_used', 'cost_sale_currency_used')
def on_change_cost_edit(self):
+ super().on_change_cost_edit()
if self.cost_edit:
- self.cost = self.cost_used
self.cost_sale = self.cost_sale_used
self.cost_sale_currency = self.cost_sale_currency_used
@@ -214,19 +160,13 @@
cost = super()._get_shipment_cost()
methods = {
m.sale.shipment_cost_method for m in self.outgoing_moves if m.sale}
- if methods == {None}:
- cost += self.cost_used or 0
if 'shipment' in methods:
if self.cost_sale:
cost_sale = Currency.compute(
self.cost_sale_currency, self.cost_sale,
self.company.currency, round=False)
- else:
- cost_sale = 0
- delta = cost_sale - (self.cost_used or 0)
- if delta < 0:
- cost -= delta
- if 'order' in methods and self.cost_used:
+ cost -= cost_sale
+ if 'order' in methods:
sales = {
m.sale for m in self.outgoing_moves
if m.sale and m.sale.shipment_cost_method == 'order'}
@@ -235,10 +175,7 @@
(s.cost_used or 0) for s in sale.shipments
if s.state == 'done' and s != self)
cost_sale = sale.shipment_cost_amount
- if cost_sale < shipment_cost:
- cost += self.cost_used or 0
- elif cost_sale < shipment_cost + (self.cost_used or 0):
- cost += shipment_cost + self.cost_used - cost_sale
+ cost -= max(cost_sale - shipment_cost, 0)
return cost
@classmethod
@@ -246,7 +183,6 @@
@Workflow.transition('done')
def done(cls, shipments):
for shipment in shipments:
- shipment.cost = shipment.cost_used
shipment.cost_sale = shipment.cost_sale_used
shipment.cost_sale_currency = shipment.cost_sale_currency_used
cls.save(shipments)
diff -r 12fd01814411 -r d32be8f2f739 tests/scenario_sale_shipment_cost_stock.rst
--- a/tests/scenario_sale_shipment_cost_stock.rst Mon May 03 16:05:31
2021 +0200
+++ b/tests/scenario_sale_shipment_cost_stock.rst Wed May 19 12:44:43
2021 +0200
@@ -17,7 +17,6 @@
>>> config = activate_modules([
... 'sale_shipment_cost',
... 'sale',
- ... 'stock_shipment_cost',
... ])
>>> Carrier = Model.get('carrier')
diff -r 12fd01814411 -r d32be8f2f739 tryton.cfg
--- a/tryton.cfg Mon May 03 16:05:31 2021 +0200
+++ b/tryton.cfg Wed May 19 12:44:43 2021 +0200
@@ -9,9 +9,9 @@
res
sale
stock
+ stock_shipment_cost
extras_depend:
sale_promotion
- stock_shipment_cost
xml:
sale.xml
stock.xml
diff -r 12fd01814411 -r d32be8f2f739 view/shipment_out_form.xml
--- a/view/shipment_out_form.xml Mon May 03 16:05:31 2021 +0200
+++ b/view/shipment_out_form.xml Wed May 19 12:44:43 2021 +0200
@@ -2,21 +2,12 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
- <xpath expr="/form/notebook" position="after">
- <label name="carrier"/>
- <field name="carrier"/>
- <group id="costs" col="-1" colspan="2">
- <label name="cost"/>
- <label name="cost_used"/>
- <field name="cost"/>
- <field name="cost_used"/>
- <label name="cost_sale"/>
- <label name="cost_sale_used"/>
- <field name="cost_sale"/>
- <field name="cost_sale_used"/>
- <field name="cost_sale_currency"/>
- <field name="cost_sale_currency_used"/>
- <field name="cost_edit"/>
- </group>
+ <xpath expr="//field[@name='cost_used']" position="after">
+ <label name="cost_sale"/>
+ <label name="cost_sale_used"/>
+ <field name="cost_sale"/>
+ <field name="cost_sale_used"/>
+ <field name="cost_sale_currency"/>
+ <field name="cost_sale_currency_used"/>
</xpath>
</data>