Remove domain on company.
Ensure company is copied from origin document to load. This commit refs #21471
This commit is contained in:
parent
e6fd525c42
commit
71797ac28b
67
load.py
67
load.py
|
@ -114,10 +114,13 @@ class Load(Workflow, ModelView, ModelSQL, DockMixin, CMRInstructionsMixin):
|
|||
code_readonly = fields.Function(fields.Boolean('Code Readonly'),
|
||||
'get_code_readonly')
|
||||
company = fields.Many2One('company.company', 'Company', required=True,
|
||||
states={'readonly': Eval('state') != 'draft'},
|
||||
domain=[('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1))],
|
||||
depends=['state'], select=True)
|
||||
states={
|
||||
'readonly':
|
||||
(Eval('state') != 'draft')
|
||||
| Eval('orders', [])
|
||||
| Eval('purchase')
|
||||
},
|
||||
depends=['state', 'orders', 'purchase'], select=True)
|
||||
carrier = fields.Many2One('carrier', 'Carrier', select=True,
|
||||
ondelete='RESTRICT',
|
||||
states={
|
||||
|
@ -160,11 +163,16 @@ class Load(Workflow, ModelView, ModelSQL, DockMixin, CMRInstructionsMixin):
|
|||
fields.Many2One('stock.location', 'Warehouse output'),
|
||||
'on_change_with_warehouse_output')
|
||||
orders = fields.One2Many('carrier.load.order', 'load', 'Orders',
|
||||
states={'readonly': (Eval('state') != 'draft') | (
|
||||
Not(Bool(Eval('carrier'))) & Not(Bool('carrier_info'))) |
|
||||
Not(Bool(Eval('warehouse')))
|
||||
domain=[
|
||||
('company', '=', Eval('company'))
|
||||
],
|
||||
states={
|
||||
'readonly':
|
||||
(Eval('state') != 'draft')
|
||||
| (Not(Bool(Eval('carrier'))) & Not(Bool('carrier_info')))
|
||||
| Not(Bool(Eval('warehouse')))
|
||||
},
|
||||
depends=['state', 'carrier', 'carrier_info', 'warehouse'])
|
||||
depends=['state', 'carrier', 'carrier_info', 'warehouse', 'company'])
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('confirmed', 'Confirmed'),
|
||||
|
@ -358,7 +366,8 @@ class Load(Workflow, ModelView, ModelSQL, DockMixin, CMRInstructionsMixin):
|
|||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
if not Transaction().context.get('define_carrier', False):
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@classmethod
|
||||
def default_state(cls):
|
||||
|
@ -686,10 +695,14 @@ class LoadOrder(Workflow, ModelView, ModelSQL, IncotermDocumentMixin,
|
|||
code_readonly = fields.Function(fields.Boolean('Code Readonly'),
|
||||
'get_code_readonly')
|
||||
company = fields.Many2One('company.company', 'Company', required=True,
|
||||
states={'readonly': Eval('state') != 'draft'},
|
||||
domain=[('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1))],
|
||||
depends=['state'], select=True)
|
||||
states={
|
||||
'readonly':
|
||||
(Eval('state') != 'draft')
|
||||
| Eval('shipment')
|
||||
| Eval('sale')
|
||||
| Eval('lines', [])
|
||||
},
|
||||
depends=['state', 'shipment', 'sale', 'lines'], select=True)
|
||||
date = fields.Function(fields.Date('Effective date'),
|
||||
'on_change_with_date')
|
||||
start_date = fields.DateTime('Start date',
|
||||
|
@ -1781,12 +1794,18 @@ class LoadOrder3(metaclass=PoolMeta):
|
|||
Load.update_sale_carrier(list(set(to_update)))
|
||||
|
||||
|
||||
class CarrierStateView(StateView):
|
||||
def get_view(self, wizard, state_name):
|
||||
with Transaction().set_context(define_carrier=True):
|
||||
return super().get_view(wizard, state_name)
|
||||
|
||||
|
||||
class CarrierDefine(Wizard):
|
||||
"""Define Carrier"""
|
||||
__name__ = 'carrier.load.define'
|
||||
|
||||
start = StateTransition()
|
||||
carrier = StateView('carrier.load',
|
||||
carrier = CarrierStateView('carrier.load',
|
||||
'carrier_load.load_view_simple_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Add', 'add', 'tryton-ok', default=True)])
|
||||
|
@ -1801,24 +1820,38 @@ class CarrierDefine(Wizard):
|
|||
if len(whs) > 1:
|
||||
raise UserError(gettext(
|
||||
'carrier_load.msg_carrier_load_define_many_warehouses'))
|
||||
if hasattr(Model, 'company'):
|
||||
records = Model.browse(Transaction().context['active_ids'])
|
||||
cpies = set(r.company for r in records)
|
||||
if len(cpies) > 1:
|
||||
raise UserError(gettext(
|
||||
'carrier_load.msg_carrier_load_define_many_companies'))
|
||||
return 'carrier'
|
||||
|
||||
def default_carrier(self, fields):
|
||||
Model = Pool().get(Transaction().context.get('active_model'))
|
||||
|
||||
res = {}
|
||||
records = Model.browse(Transaction().context['active_ids'])
|
||||
if hasattr(Model, 'warehouse'):
|
||||
records = Model.browse(Transaction().context['active_ids'])
|
||||
whs = set(r.warehouse and r.warehouse.id or None for r in records)
|
||||
whs = set(r.warehouse.id for r in records if r.warehouse)
|
||||
res['warehouse'] = whs.pop()
|
||||
if hasattr(Model, 'company'):
|
||||
# this does not work as default set value again
|
||||
cpies = set(r.company.id for r in records if r.company)
|
||||
res['company'] = cpies.pop()
|
||||
return res
|
||||
|
||||
def transition_add(self):
|
||||
pool = Pool()
|
||||
Model = pool.get(Transaction().context.get('active_model'))
|
||||
|
||||
self.carrier.save()
|
||||
records = Model.browse(Transaction().context['active_ids'])
|
||||
if hasattr(Model, 'company'):
|
||||
company, = set(r.company for r in records if r.company)
|
||||
if self.carrier.company != company:
|
||||
self.carrier.company = company
|
||||
self.carrier.save()
|
||||
Model.write(records, {
|
||||
'planned_carrier_loads': [('add', [self.carrier.id])]
|
||||
})
|
||||
|
|
|
@ -57,6 +57,10 @@ msgctxt "model:ir.message,text:msg_carrier_load_define_many_warehouses"
|
|||
msgid "Warehouse must match."
|
||||
msgstr "Almacén debe coincidir."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_carrier_load_define_many_companies"
|
||||
msgid "Company must match."
|
||||
msgstr "Empresa debe coincidir."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_carrier_load_order_no_sale_line_found"
|
||||
msgid ""
|
||||
"Cannot find a line on Sale \"%(sale)s\" with following data:\n"
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<record model="ir.message" id="msg_carrier_load_define_many_warehouses">
|
||||
<field name="text">Warehouse must match.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_carrier_load_define_many_companies">
|
||||
<field name="text">Company must match.</field>
|
||||
</record>
|
||||
|
||||
<!-- carrier.load.order -->
|
||||
<record model="ir.message" id="msg_carrier_load_order_no_sale_line_found">
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<field name="warehouse"/>
|
||||
<label name="dock"/>
|
||||
<field name="dock"/>
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<newline/>
|
||||
<label name="purchasable"/>
|
||||
<field name="purchasable"/>
|
||||
<label name="purchase"/>
|
||||
|
|
Loading…
Reference in New Issue