Add cost prefix to all sale shipment cost fields
This improves the naming convention and avoid collisions or misinterpretations.
This commit is contained in:
@@ -8,6 +8,6 @@ from trytond.pool import PoolMeta
|
||||
class InvoiceLine(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice.line'
|
||||
|
||||
cost_shipment_carriages = fields.One2Many(
|
||||
'stock.shipment.carriage', 'cost_invoice_line',
|
||||
"Cost of Shipment Carriages", readonly=True)
|
||||
cost_sale_shipment_carriages = fields.One2Many(
|
||||
'stock.shipment.carriage', 'cost_sale_invoice_line',
|
||||
"Cost Sale of Shipment Carriages", readonly=True)
|
||||
|
||||
@@ -124,7 +124,7 @@ class Line(metaclass=PoolMeta):
|
||||
invoice = self.sale._get_invoice_sale()
|
||||
for carriage in shipment.carriages:
|
||||
# XXX: self is not necessary linked to carriage
|
||||
invoice_line = carriage.get_cost_invoice_line(
|
||||
invoice_line = carriage.get_cost_sale_invoice_line(
|
||||
invoice, origin=self)
|
||||
if invoice_line:
|
||||
lines.append(invoice_line)
|
||||
|
||||
@@ -43,6 +43,16 @@ class Carriage(sequence_ordered(), ShipmentCostMixin, ModelSQL, ModelView):
|
||||
super().__setup__()
|
||||
cls.carrier.required = True
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module):
|
||||
table_h = cls.__table_handler__(module)
|
||||
|
||||
# Migration from 7.2: use suffix sale
|
||||
table_h.column_rename('cost_method', 'cost_sale_method')
|
||||
table_h.column_rename('cost_invoice_line', 'cost_sale_invoice_line')
|
||||
|
||||
super().__register__(module)
|
||||
|
||||
@classmethod
|
||||
def get_shipments(cls):
|
||||
pool = Pool()
|
||||
@@ -159,10 +169,11 @@ class Carriage_Sale(ShipmentCostSaleMixin, metaclass=PoolMeta):
|
||||
def _shipment_cost_currency_date(self):
|
||||
return self.shipment.effective_date
|
||||
|
||||
def get_cost_invoice_line(self, invoice, origin=None):
|
||||
invoice_line = super().get_cost_invoice_line(invoice, origin=origin)
|
||||
def get_cost_sale_invoice_line(self, invoice, origin=None):
|
||||
invoice_line = super().get_cost_sale_invoice_line(
|
||||
invoice, origin=origin)
|
||||
if invoice_line:
|
||||
invoice_line.cost_shipment_carriages = [self]
|
||||
invoice_line.cost_sale_shipment_carriages = [self]
|
||||
return invoice_line
|
||||
|
||||
@classmethod
|
||||
@@ -171,7 +182,7 @@ class Carriage_Sale(ShipmentCostSaleMixin, metaclass=PoolMeta):
|
||||
sequence=carriage.sequence,
|
||||
type=carriage.type,
|
||||
carrier=carriage.carrier,
|
||||
cost_method=carriage.cost_method,
|
||||
cost_sale_method=carriage.cost_method,
|
||||
from_=carriage.from_,
|
||||
to=carriage.to,
|
||||
)
|
||||
|
||||
@@ -147,10 +147,10 @@ Send products::
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
>>> shipment.cost_invoice_line.amount
|
||||
>>> shipment.cost_sale_invoice_line.amount
|
||||
Decimal('3.00')
|
||||
>>> carriage, = shipment.before_carriages
|
||||
>>> carriage.cost_invoice_line.amount
|
||||
>>> carriage.cost_sale_invoice_line.amount
|
||||
Decimal('2.00')
|
||||
|
||||
Check customer invoice::
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Add sale prefix to all fields
|
||||
|
||||
Version 7.2.0 - 2024-04-29
|
||||
--------------------------
|
||||
|
||||
@@ -7,8 +7,9 @@ from trytond.pool import PoolMeta
|
||||
class InvoiceLine(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice.line'
|
||||
|
||||
cost_shipments = fields.One2Many(
|
||||
'stock.shipment.out', 'cost_invoice_line', "Cost of Shipments",
|
||||
cost_sale_shipments = fields.One2Many(
|
||||
'stock.shipment.out', 'cost_sale_invoice_line',
|
||||
"Cost Sale of Shipments",
|
||||
readonly=True)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -371,7 +371,7 @@ class Sale(metaclass=PoolMeta):
|
||||
fields = super()._get_shipment_grouping_fields(shipment)
|
||||
fields.add('carrier')
|
||||
if isinstance(shipment, ShipmentOut):
|
||||
fields.add('cost_method')
|
||||
fields.add('cost_sale_method')
|
||||
return fields
|
||||
|
||||
@property
|
||||
@@ -387,7 +387,7 @@ class Sale(metaclass=PoolMeta):
|
||||
ShipmentOut = pool.get('stock.shipment.out')
|
||||
shipment = super()._get_shipment_sale(Shipment, key)
|
||||
if isinstance(shipment, ShipmentOut):
|
||||
shipment.cost_method = self.shipment_cost_method
|
||||
shipment.cost_sale_method = self.shipment_cost_method
|
||||
shipment.carrier = self.carrier
|
||||
return shipment
|
||||
|
||||
@@ -433,7 +433,7 @@ class Line(metaclass=PoolMeta):
|
||||
for shipment in self.sale.shipments:
|
||||
if (shipment.state == 'done'
|
||||
and shipment.id not in shipment_cost_invoiced):
|
||||
invoice_line = shipment.get_cost_invoice_line(
|
||||
invoice_line = shipment.get_cost_sale_invoice_line(
|
||||
self.sale._get_invoice_sale(), origin=self)
|
||||
if invoice_line:
|
||||
lines.append(invoice_line)
|
||||
@@ -455,7 +455,8 @@ class Line(metaclass=PoolMeta):
|
||||
elif (self.sale.shipment_cost_method == 'order'
|
||||
and self.sale.invoice_method == 'shipment'):
|
||||
shipments = [
|
||||
s for s in self.sale.shipments if s.cost_method == 'order']
|
||||
s for s in self.sale.shipments
|
||||
if s.cost_sale_method == 'order']
|
||||
if (not shipments
|
||||
or all(s.state != 'done' for s in shipments)):
|
||||
quantity = 0
|
||||
|
||||
@@ -16,7 +16,7 @@ class ShipmentCostSaleMixin:
|
||||
cost_sale_currency_used = fields.Function(fields.Many2One(
|
||||
'currency.currency', "Cost Sale Currency",
|
||||
states={
|
||||
'invisible': Eval('cost_method') != 'shipment',
|
||||
'invisible': Eval('cost_sale_method') != 'shipment',
|
||||
'readonly': (
|
||||
Eval('shipment_cost_sale_readonly', True)
|
||||
| ~Eval('cost_edit', False)),
|
||||
@@ -25,14 +25,14 @@ class ShipmentCostSaleMixin:
|
||||
cost_sale_currency = fields.Many2One(
|
||||
'currency.currency', "Cost Sale Currency",
|
||||
states={
|
||||
'invisible': Eval('cost_method') != 'shipment',
|
||||
'invisible': Eval('cost_sale_method') != 'shipment',
|
||||
'required': Bool(Eval('cost_sale')),
|
||||
'readonly': Eval('shipment_cost_sale_readonly', True),
|
||||
})
|
||||
cost_sale_used = fields.Function(fields.Numeric(
|
||||
"Cost Sale", digits=price_digits,
|
||||
states={
|
||||
'invisible': Eval('cost_method') != 'shipment',
|
||||
'invisible': Eval('cost_sale_method') != 'shipment',
|
||||
'readonly': (
|
||||
Eval('shipment_cost_sale_readonly', True)
|
||||
| ~Eval('cost_edit', False)),
|
||||
@@ -41,16 +41,16 @@ class ShipmentCostSaleMixin:
|
||||
cost_sale = fields.Numeric(
|
||||
"Cost Sale", digits=price_digits, readonly=True,
|
||||
states={
|
||||
'invisible': Eval('cost_method') != 'shipment',
|
||||
'invisible': Eval('cost_sale_method') != 'shipment',
|
||||
})
|
||||
|
||||
cost_sales = fields.One2Many(
|
||||
'stock.shipment.cost_sale', 'shipment', "Cost Sales", readonly=True)
|
||||
|
||||
cost_invoice_line = fields.Many2One(
|
||||
'account.invoice.line', "Cost Invoice Line", readonly=True)
|
||||
cost_method = fields.Selection(
|
||||
'get_cost_methods', "Cost Method", readonly=True)
|
||||
cost_sale_invoice_line = fields.Many2One(
|
||||
'account.invoice.line', "Cost Sale Invoice Line", readonly=True)
|
||||
cost_sale_method = fields.Selection(
|
||||
'get_cost_sale_methods', "Cost Sale Method", readonly=True)
|
||||
|
||||
shipment_cost_sale_readonly = fields.Function(
|
||||
fields.Boolean("Shipment Cost Sale Read Only"),
|
||||
@@ -59,14 +59,15 @@ class ShipmentCostSaleMixin:
|
||||
def on_change_with_shipment_cost_sale_readonly(self, name=None):
|
||||
raise NotImplementedError
|
||||
|
||||
@fields.depends('carrier', 'cost_method', methods=['_get_carrier_context'])
|
||||
@fields.depends(
|
||||
'carrier', 'cost_sale_method', methods=['_get_carrier_context'])
|
||||
def _compute_costs(self):
|
||||
costs = super()._compute_costs()
|
||||
costs.update({
|
||||
'cost_sale': None,
|
||||
'cost_sale_currency': None,
|
||||
})
|
||||
if self.carrier and self.cost_method == 'shipment':
|
||||
if self.carrier and self.cost_sale_method == 'shipment':
|
||||
with Transaction().set_context(self._get_carrier_context()):
|
||||
cost_sale, sale_currency_id = self.carrier.get_sale_price()
|
||||
if cost_sale is not None:
|
||||
@@ -93,21 +94,21 @@ class ShipmentCostSaleMixin:
|
||||
return self.cost_sale_currency
|
||||
|
||||
@classmethod
|
||||
def get_cost_methods(cls):
|
||||
def get_cost_sale_methods(cls):
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
fieldname = 'shipment_cost_method'
|
||||
return Sale.fields_get([fieldname])[fieldname]['selection']
|
||||
|
||||
def get_cost_invoice_line(self, invoice, origin=None):
|
||||
def get_cost_sale_invoice_line(self, invoice, origin=None):
|
||||
pool = Pool()
|
||||
Currency = pool.get('currency.currency')
|
||||
InvoiceLine = pool.get('account.invoice.line')
|
||||
|
||||
if (self.cost_method != 'shipment'
|
||||
if (self.cost_sale_method != 'shipment'
|
||||
or not self.carrier
|
||||
or not self.cost_sale_used
|
||||
or self.cost_invoice_line):
|
||||
or self.cost_sale_invoice_line):
|
||||
return
|
||||
product = self.carrier.carrier_product
|
||||
|
||||
@@ -189,14 +190,18 @@ class ShipmentOut(ShipmentCostSaleMixin, metaclass=PoolMeta):
|
||||
and not table_h.column_exist('cost_sale_currency')):
|
||||
table_h.column_rename('cost_currency', 'cost_sale_currency')
|
||||
|
||||
cost_method_exists = table_h.column_exist('cost_method')
|
||||
# Migration from 7.2: use suffix sale
|
||||
table_h.column_rename('cost_method', 'cost_sale_method')
|
||||
table_h.column_rename('cost_invoice_line', 'cost_sale_invoice_line')
|
||||
|
||||
cost_sale_method_exists = table_h.column_exist('cost_sale_method')
|
||||
|
||||
super().__register__(module)
|
||||
|
||||
# Migration from 6.0: fill new cost_method field
|
||||
if not cost_method_exists:
|
||||
# Migration from 6.0: fill new cost_sale_method field
|
||||
if not cost_sale_method_exists:
|
||||
cursor.execute(*table.update(
|
||||
columns=[table.cost_method],
|
||||
columns=[table.cost_sale_method],
|
||||
values=['shipment']))
|
||||
|
||||
@fields.depends('state')
|
||||
@@ -207,10 +212,11 @@ class ShipmentOut(ShipmentCostSaleMixin, metaclass=PoolMeta):
|
||||
def _shipment_cost_currency_date(self):
|
||||
return self.effective_date
|
||||
|
||||
def get_cost_invoice_line(self, invoice, origin=None):
|
||||
invoice_line = super().get_cost_invoice_line(invoice, origin=origin)
|
||||
def get_cost_sale_invoice_line(self, invoice, origin=None):
|
||||
invoice_line = super().get_cost_sale_invoice_line(
|
||||
invoice, origin=origin)
|
||||
if invoice_line:
|
||||
invoice_line.cost_shipments = [self]
|
||||
invoice_line.cost_sale_shipments = [self]
|
||||
return invoice_line
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -140,7 +140,7 @@ Send products::
|
||||
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
>>> shipment, = sale.shipments
|
||||
>>> shipment.cost_method
|
||||
>>> shipment.cost_sale_method
|
||||
'shipment'
|
||||
>>> assertEqual(shipment.carrier, carrier)
|
||||
>>> shipment.cost_used
|
||||
@@ -168,7 +168,7 @@ Send products::
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
>>> shipment.cost_invoice_line.amount
|
||||
>>> shipment.cost_sale_invoice_line.amount
|
||||
Decimal('3.00')
|
||||
|
||||
Check customer invoice::
|
||||
|
||||
@@ -24,7 +24,7 @@ class SaleShipmentCostTestCase(ModuleTestCase):
|
||||
|
||||
fields = sale._get_shipment_grouping_fields(shipment)
|
||||
|
||||
self.assertLessEqual({'cost_method', 'carrier'}, fields)
|
||||
self.assertLessEqual({'cost_sale_method', 'carrier'}, fields)
|
||||
self.assertLessEqual(fields, ShipmentOut._fields.keys())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user