Invoice Melya template
This commit is contained in:
@@ -1404,23 +1404,11 @@ class Invoice(metaclass=PoolMeta):
|
||||
shipment = self._get_report_shipment()
|
||||
if not shipment:
|
||||
return ''
|
||||
supplier = getattr(shipment, 'supplier', None)
|
||||
if getattr(shipment, 'transport_type', None) == 'truck':
|
||||
return 'By Truck'
|
||||
vessel = getattr(shipment, 'vessel', None)
|
||||
supplier_name = (
|
||||
getattr(supplier, 'name', None)
|
||||
or getattr(supplier, 'rec_name', None)
|
||||
or '')
|
||||
vessel_name = getattr(vessel, 'vessel_name', None) or ''
|
||||
note = getattr(shipment, 'note', None) or ''
|
||||
|
||||
if supplier_name and vessel_name:
|
||||
transport = f"BY {supplier_name} ({vessel_name})"
|
||||
elif supplier_name:
|
||||
transport = f"BY {supplier_name}"
|
||||
else:
|
||||
transport = vessel_name
|
||||
|
||||
return ' '.join(part for part in [transport, note] if part).strip()
|
||||
return vessel_name
|
||||
|
||||
@property
|
||||
def report_bl_date(self):
|
||||
|
||||
@@ -684,7 +684,8 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
('truck', 'Truck'),
|
||||
('other', 'Other'),
|
||||
], 'Transport type')
|
||||
vessel = fields.Many2One('trade.vessel',"Vessel")
|
||||
vessel = fields.Many2One('trade.vessel', "Vessel",
|
||||
states={'invisible': Eval('transport_type') == 'truck'})
|
||||
info = fields.Function(fields.Text("Info",states={'invisible': ~Eval('info',False)}),'get_info')
|
||||
anim = fields.Function(fields.Text(""),'get_anim')
|
||||
carte = fields.Function(fields.Text("",states={'invisible': ~Eval('info',False)}),'get_imo')
|
||||
@@ -725,12 +726,17 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
travel_nb = fields.Char("Travel nb")
|
||||
receive_date = fields.Date("Reception date")
|
||||
receive_nb = fields.Char("Reception nb")
|
||||
cargo_mode = fields.Selection([
|
||||
('bulk', 'Bulk'),
|
||||
('container', 'Container'),
|
||||
], 'Cargo Mode', required=True)
|
||||
|
||||
vessel_type = fields.Function(fields.Many2One('stock.vessel.type',"Vessel type"),'get_vessel_type')
|
||||
cargo_mode = fields.Selection([
|
||||
('none', ''),
|
||||
('bulk', 'Bulk'),
|
||||
('container', 'Container'),
|
||||
], 'Cargo Mode', required=True,
|
||||
states={'invisible': Eval('transport_type') == 'truck'})
|
||||
|
||||
vessel_type = fields.Function(
|
||||
fields.Many2One('stock.vessel.type', "Vessel type",
|
||||
states={'invisible': Eval('transport_type') == 'truck'}),
|
||||
'get_vessel_type')
|
||||
container = fields.One2Many(
|
||||
'stock.shipment.container',
|
||||
'shipment',
|
||||
@@ -760,6 +766,35 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
'send': {},
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def _normalize_transport_values(values, record=None):
|
||||
values = dict(values)
|
||||
transport_type = values.get(
|
||||
'transport_type', getattr(record, 'transport_type', None))
|
||||
if transport_type == 'truck':
|
||||
values['vessel'] = None
|
||||
values['cargo_mode'] = 'none'
|
||||
elif values.get('cargo_mode') == 'none':
|
||||
values['cargo_mode'] = 'bulk'
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
return super().create([
|
||||
cls._normalize_transport_values(values) for values in vlist])
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
new_args = []
|
||||
for index in range(0, len(args), 2):
|
||||
records = args[index]
|
||||
values = args[index + 1]
|
||||
for record in records:
|
||||
new_args.extend([
|
||||
[record],
|
||||
cls._normalize_transport_values(values, record)])
|
||||
super().write(*new_args)
|
||||
|
||||
@classmethod
|
||||
def _stock_move_origin(cls, move):
|
||||
return 'stock.move,%s' % move.id
|
||||
@@ -1693,9 +1728,21 @@ class ShipmentIn(metaclass=PoolMeta):
|
||||
def get_sh(self, name):
|
||||
return self.id
|
||||
|
||||
@classmethod
|
||||
def default_transport_type(cls):
|
||||
return 'vessel'
|
||||
@classmethod
|
||||
def default_transport_type(cls):
|
||||
return 'vessel'
|
||||
|
||||
@classmethod
|
||||
def default_cargo_mode(cls):
|
||||
return 'bulk'
|
||||
|
||||
@fields.depends('transport_type', 'cargo_mode', 'vessel')
|
||||
def on_change_transport_type(self):
|
||||
if self.transport_type == 'truck':
|
||||
self.vessel = None
|
||||
self.cargo_mode = 'none'
|
||||
elif self.cargo_mode == 'none':
|
||||
self.cargo_mode = 'bulk'
|
||||
|
||||
@classmethod
|
||||
def default_dashboard(cls):
|
||||
|
||||
@@ -5081,6 +5081,59 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(invoice.report_si_number, 'SI-B')
|
||||
self.assertEqual(invoice.report_si_reference, 'REF-B')
|
||||
|
||||
def test_shipment_in_truck_defaults_empty_cargo_mode(self):
|
||||
'truck shipment clears vessel data and uses empty cargo mode'
|
||||
ShipmentIn = Pool().get('stock.shipment.in')
|
||||
|
||||
shipment = ShipmentIn()
|
||||
shipment.transport_type = 'truck'
|
||||
shipment.vessel = Mock()
|
||||
shipment.cargo_mode = 'bulk'
|
||||
|
||||
shipment.on_change_transport_type()
|
||||
|
||||
self.assertIsNone(shipment.vessel)
|
||||
self.assertEqual(shipment.cargo_mode, 'none')
|
||||
self.assertEqual(
|
||||
ShipmentIn._normalize_transport_values({
|
||||
'transport_type': 'truck',
|
||||
'cargo_mode': 'bulk',
|
||||
'vessel': 42,
|
||||
}),
|
||||
{
|
||||
'transport_type': 'truck',
|
||||
'cargo_mode': 'none',
|
||||
'vessel': None,
|
||||
})
|
||||
|
||||
def test_invoice_report_transportation_uses_truck_label(self):
|
||||
'invoice_melya Transportation displays By Truck for truck shipments'
|
||||
Invoice = Pool().get('account.invoice')
|
||||
|
||||
invoice = Invoice()
|
||||
invoice._get_report_shipment = Mock(return_value=Mock(
|
||||
transport_type='truck',
|
||||
supplier=Mock(rec_name='SUPPLIER'),
|
||||
vessel=Mock(vessel_name='VESSEL A'),
|
||||
note='ignored',
|
||||
))
|
||||
|
||||
self.assertEqual(invoice.report_transportation, 'By Truck')
|
||||
|
||||
def test_invoice_report_transportation_uses_vessel_name_only(self):
|
||||
'invoice_melya Transportation displays only vessel name for vessels'
|
||||
Invoice = Pool().get('account.invoice')
|
||||
|
||||
invoice = Invoice()
|
||||
invoice._get_report_shipment = Mock(return_value=Mock(
|
||||
transport_type='vessel',
|
||||
supplier=Mock(rec_name='SUPPLIER'),
|
||||
vessel=Mock(vessel_name='VESSEL A'),
|
||||
note='ignored',
|
||||
))
|
||||
|
||||
self.assertEqual(invoice.report_transportation, 'VESSEL A')
|
||||
|
||||
def test_invoice_report_shipment_is_blank_if_invoice_mixes_shipments(self):
|
||||
'invoice shipment fields stay empty when multiple shipments are invoiced together'
|
||||
Invoice = Pool().get('account.invoice')
|
||||
|
||||
Reference in New Issue
Block a user