Skip to Content
Menu
This question has been flagged
6 Replies
6104 Views

i want to display only the products that has as a status = 'qualifid' when i am creating a new sales order in the sales.order.lines form 

for this i added the new selection field in the product.template model 

_inherit = "product.template"

    state = fields.Selection([
        ('scratch', 'Brouillion'),
        ('qualifid', 'Qualifié'),
        ('valide', 'Validé'),
        ], setting='State', readonly=True, default='scratch')

i added the field to the correspanding view 

<record id="view_product_template_tech_inherit" model="ir.ui.view">
<field name="name">product.template.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="/form/header/button" position="after">
<field name="state" widget="statusbar"/>
</xpath>
</field>
</record>

and then i try to set the product_id in with this domaine 

<record id="view_sale_order_tech_inherit" model="ir.ui.view">
<field name="name">tech.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath
expr="//page[@name='order_lines']/field/form/group/group/field[@name='product_id']" position="replace">
<field name="product_id" domain="[('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id), ('state', '!=', 'scratch')]"/>
</xpath>
</field>
</record>

but it seems something still missing 

Avatar
Discard
Best Answer

Hi,

Please try Below Code.

<xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='product_id']" position="attributes">
<attribute name="domain">['&amp;',('state', '=', 'scratch'),('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]</attribute>

</xpath>


Avatar
Discard
Author

hi, i tried your suggestion and it seems somthing wrong

File "src/lxml/parser.pxi", line 600, in lxml.etree._ParserContext._handleParseResultDoc

File "src/lxml/parser.pxi", line 710, in lxml.etree._handleParseResult

File "src/lxml/parser.pxi", line 639, in lxml.etree._raiseParseError

File "/usr/lib/python3/dist-packages/odoo/addons/tech_sale/views/tech_sale.xml", line 22

lxml.etree.XMLSyntaxError: xmlParseEntityRef: no name, line 22, column 29

Sorry forgot to specify '&' to '&amp;' , answer updated , Try it.

Author

yes, the error occured due to a syntax error, thanks, i'll mark it as a best answer

Best Answer

Hi,

If there is no errors in installation of the module, make sure that the given domain for the field is correct, just ensure that the OR statement is placed correctly.


Also checking the code, it seems you are applying domain by xpath the one2many form view, so are you checking from the one2many form itself ? If not apply the same domain in the one2many tree view also, or you can directly apply the domain inheriting the sale.order.line in python file itself.


Sample xpath of sale order line view,

<xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='name']" position="after">
<field name="field_name"/>
</xpath>


Thanks

Avatar
Discard
Author

i tried to change the order of the domain conditions, by setting the ('state', '!=', 'scratch') first i had this error

odoo.tools.convert.ParseError: "unexpected EOF while parsing

('<unknown>', 1, 123, "('state', '=', 'scratch'), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id), ('sale_ok', '=', True)]")" while parsing /usr/lib/python3/dist-packages/odoo/addons/tech_sale/views/tech_sale.xml:2, near

<odoo>

odoo.tools.convert.ParseError: "unexpected EOF while parsing

('<unknown>', 1, 123, "('state', '=', 'scratch'), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id), ('sale_ok', '=', True)]")" while parsing /usr/lib/python3/dist-packages/odoo/addons/tech_sale/views/tech_sale.xml:2, near

<odoo>

it could be just the syntaxe ?

yes given syntax is wrong

Author

any suggestion please ?

Related Posts Replies Views Activity
1
Oct 20
2350
2
Mar 15
5444
1
Mar 15
2681
0
Mar 15
2814
1
Mar 21
5012