Skip to Content
Menu
This question has been flagged
2 Replies
4472 Views

In Odoo V10, I am editing the default sale.order.form.sale.stock. Here is the full original view:


 <?xml version="1.0" encoding="UTF-8"?><data> <xpath expr="//button[@name='action_view_invoice']" position="before"> <field name="picking_ids" invisible="1" /> <button type="object" name="action_view_delivery" class="oe_stat_button" icon="fa-truck" attrs="{'invisible': [('delivery_count', '=', 0)]}" groups="base.group_user"> <field name="delivery_count" widget="statinfo" string="Delivery" /> </button> </xpath> <xpath expr="//group[@name='sales_person']" position="before"> <group string="Shipping Information" name="sale_shipping"> <field name="warehouse_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations" /> <field name="incoterm" widget="selection" groups="base.group_user" /> <field name="picking_policy" required="True" /> </group> </xpath> <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='tax_id']" position="before"> <field name="product_tmpl_id" invisible="1" /> <field name="product_packaging" context="{'default_product_tmpl_id': product_tmpl_id, 'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging" /> </xpath> <xpath expr="//field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before"> <field name="route_id" groups="sale_stock.group_route_so_lines" /> </xpath> <xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="before"> <field name="route_id" groups="sale_stock.group_route_so_lines" /> </xpath></data>


I am simply trying to edit the last field, to add a domain like this:

<field name="route_id" groups="sale_stock.group_route_so_lines" domain="[('product_ids', 'in', product_tmpl_id)]"/>

However, when I click into the Routes field in the UI, I get the error:

Uncaught Error: AttributeError: object has no attribute 'product_tmpl_id'

Why would this error be occurring? The sale.order.line object has a product_tmpl_id field, so why am I getting an error that it does not have that attribute?


Avatar
Discard
Best Answer

per Odoo documentation a domain consists of ( field_name,  operator,  value ) triplets. As you can see here, field name is used in a leftmost part of triplet, an operator in the middle and a value at the right part. However you're trying to use field name in the right part, that is NOT a supported usage of domain, Odoo expects some variable value in this part, not a field name, so you can't put it there.

If you want to achieve such a complicated domain, you might consider to add a computed boolean field, than do your computation inside that field and than use the field in the domain, like domain="[('my_field', '=', True)]" and you're done.

to have my_field available for such a domain, you should have added something like:

my_field = fields.Boolean("Some Flag", compute="compute_my_field")

@api.multi
@api.depends("product_ids", "product_tmpl_id")
def compute_my_field(self):
for rec in self:
rec.my_field = rec.product_ids and rec.product_tmpl_id in rec.product_ids or False
Avatar
Discard
Best Answer

dear Michael Leff,


try this:

<field name="route_id" groups="sale_stock.group_route_so_lines" domain="[('product_ids', 'in', [product_tmpl_id])]"/>

I hope i helped you...

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 16
4903
5
Aug 24
42968
2
Apr 24
948
3
Jun 23
3123
2
Jun 23
2362