Hi folks;
I was wondering to get some help here. I have a field called "container_id" which have an attribute"transport" on Sale.Order form. Basically this show me what kind of transport have that container (container_id.transport). This works good but the tricky part goes when i want to find that attribute from Sale.Order.Line on a _onchange method to validate what kind of transport is.
What im trying is, basically, when im doing the math calculation to see the Volume (exp_vol) before i want to check if the container_id.transport is air or not because the formula changes.
Attached i send you my code and screen captures. Thanks so much for your help. I am pretty sure i am not the only one trying to get some field from the top to Sale.Order.Line. Thanks in advance
XML
<record id="view_freight_operation_form" model="ir.ui.view">
<field name="name">view.freight.operation.form</field>
<field name="model">freight.operation</field>
<field name="arch" type="xml">
<form string="Freight">
<sheet>
<label for="name" string="Name"/>
<field name="container_id"/>
<notebook>
<page string="Packaging">
<field name="operation_line_ids" attrs="{'readonly': [('state','not in',['draft'])]}">
<tree editable="top">
<field name="length" string="L (in)"/>
<field name="width" string="W (in)"/>
<field name="height" string="H (in)"/>
<field name="exp_vol" sum="Total Volume" readonly="1" force_save="1"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
PY
class FreightOperation(models.Model):
"""Freight Operation Model"""
_name = 'freight.operation'
_description = 'Freight Operations'
container_id = fields.Many2one('freight.container', string="Container")
class FreightOperationLine(models.Model):
"""Freight Operation Line Model"""
_name = 'freight.operation.line'
_description = 'Order Line'
container_id = fields.Many2one('freight.container', string="Container")
length = fields.Float(string='Length')
width = fields.Float(string='Width')
height = fields.Float(string='Height')
exp_vol = fields.Float(string="Volume")
@api.onchange('length', 'width', 'height')
def _onchange_length(self):
for operation in self:
if operation.container_id.transport == 'air':
for line in self:
line.exp_vol = line.length * line.width * line.height / 166
else:
for line in self:
line.exp_vol = line.length * line.width * line.height / 1728