I need to make the radio button option to only "container" when the values of direction='export', transport='ocean' and ocean_shipment_type='fcl'.
Here are the snippets of models involved:
class FreightShipment(models.Model):
_name = 'freight.shipment'
direction = fields.Selection(([('import', 'Import'), ('export', 'Export')]), string='Direction' )
transport = fields.Selection(([('air', 'Air'), ('ocean', 'Ocean'), ('land', 'Land')]),
string='Transport Via')
ocean_shipment_type = fields.Selection(([('fcl', 'Full Container(FCL)'),
('lcl', 'Less Container(LCL)')]),
string='Ocean Shipment Type')
freight_packages = fields.One2many( 'shipment.package.line', 'shipment_id')
class ShipmentPackageLine(models.Model):
_name = 'shipment.package.line'
_rec_name = 'package'
package_type = fields.Selection([('item', 'Loose Cargo'), ('container', 'Containerized')] ,
string="Package Type", default='item')
...
Here is the XML view snippet:
<record model="ir.ui.view" id="freight_shipment_form_view">
<field name="name">freight.shipment.form.view</field>
<field name="model">freight.shipment</field >
...
<sheet>
...
<div class="oe_title mb24">
<h1>
<field class="text-break" name="name" default_focus="1" readonly="1"/>
</ h1>
<h3>
<field name="direction" widget="radio" required="1" options="{'horizontal': true}"/>
</h3>
</div>
...
<group string="Transport Details">
<field name="is_transport_read_only" invisible="1" />
<group>
<field name="transport" widget="radio" options="{'horizontal': true}" required="1" readonly="is_transport_read_only"/>
</group>
<group>
<field name ="ocean_shipment_type" invisible="shipment != 'ocean'" required="shipment == 'ocean'"/>
<field name="inland_shipment_type" invisible="transport != 'land'" required="transport == 'land'"/>
</group>
</group>
...
<notebook>
...
<page string="Package Details" invisible="direction != 'export'">
<field name="freight_packages" nolabel="1" widget="one2many_list">
<tree string="Package">
<field name="name" required="1 "/>
...
</tree>
<form string="Package">
<group>
<label for="package_type"/>
<div>
<field name="package_type" widget="radio" options="{'horizontal':True}"/>
</div>
</group>
<group invisible="package_type != 'container'">
<group string="Containerized">
<field name="name" required="1"/>
</group>
...
<group invisible="package_type != 'item'">
<group string="Loose Cargo">
<field name="name" required="1"/>
</group>
...
Here is the solution Microsoft pilot recommended but this not worked.
# Package type options
@api.onchange('direction', 'transport', 'ocean_shipment_type')
def _onchange_shipment_conditions(self):
for package in self.freight_packages:
if self.direction == 'export' and self.transport == ' ocean' and self.ocean_shipment_type == 'fcl':
package.package_type = 'container'
package.fields_get()['package_type']['selection'] = [('container', 'Containerized')]
else:
package.fields_get()['package_type']['selection'] = [('item', 'Loose Cargo'), ('container', 'Containerized')]
How to fix my issue?
Sehr geehrte Damen und Herren,
ich bin bis einschließlich 03.01.2025 nicht im Büro. Eingehende E-Mails werden nicht zeitnah bearbeitet oder weitergeleitet.
Für dringende allgemeine Anfragen bitte ich Sie unsere Info-E-Mail-Adresse zu verwenden (info@be4energ.com).
Für Angebotsanfrage oder Fragen zu Projekten oder Planungen ist unser Projektierungsteam (projects@be4energy.com) für Sie erreichbar.
Mit herzlichem Gruße
Stefan Galler
Dear Sir or Madam,
I will be out of the office until January 3rd, 2025. Incoming emails will not be processed or forwarded promptly.
For urgent general inquiries, please use our general email address (info@be4energ.com).
For requests for quotations or questions regarding projects or planning, our project planning team (projects@be4energy.com) is available to assist you.
With kind regards,
Stefan Galler