diff --git a/doc/index.rst b/doc/index.rst index ccda7361be..0ae99d4a55 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -15,9 +15,3 @@ Two new fields are added to *Sale* and *Sale Configuration*: 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 --git a/setup.py b/setup.py index 156291259f..9f91798ba4 100755 --- a/setup.py +++ b/setup.py @@ -65,7 +65,6 @@ requires.append(get_require_version('trytond')) 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 --git a/stock.py b/stock.py index 498fe7900b..7b2154c393 100644 --- a/stock.py +++ b/stock.py @@ -12,66 +12,34 @@ from .exceptions import InvoiceShipmentCostError 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 @@ class ShipmentOut(metaclass=PoolMeta): 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 @@ class ShipmentOut(metaclass=PoolMeta): 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 @@ class ShipmentOut(metaclass=PoolMeta): 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 @@ class ShipmentOut(metaclass=PoolMeta): (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 @@ class ShipmentOut(metaclass=PoolMeta): @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 --git a/tests/scenario_sale_shipment_cost_stock.rst b/tests/scenario_sale_shipment_cost_stock.rst index 6c3a881c76..784874bc80 100644 --- a/tests/scenario_sale_shipment_cost_stock.rst +++ b/tests/scenario_sale_shipment_cost_stock.rst @@ -17,7 +17,6 @@ Activate modules:: >>> config = activate_modules([ ... 'sale_shipment_cost', ... 'sale', - ... 'stock_shipment_cost', ... ]) >>> Carrier = Model.get('carrier') diff --git a/tryton.cfg b/tryton.cfg index 7b827f6cdc..c96422b98b 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -9,9 +9,9 @@ depends: res sale stock + stock_shipment_cost extras_depend: sale_promotion - stock_shipment_cost xml: sale.xml stock.xml diff --git a/view/shipment_out_form.xml b/view/shipment_out_form.xml index 2c47f20b21..66a7ee99be 100644 --- a/view/shipment_out_form.xml +++ b/view/shipment_out_form.xml @@ -2,21 +2,12 @@ - -