Se rendre au contenu
Menu
Cette question a été signalée
6 Réponses
7579 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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.

Auteur

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

Meilleure réponse

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
Ignorer
Auteur

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 ?

Auteur

any suggestion please ?

Publications associées Réponses Vues Activité
0
févr. 25
18
1
oct. 20
3449
2
mars 15
6942
0
mars 15
3839
1
mars 15
3826