Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
7401 Lượt xem

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 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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>


Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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 ?

Tác giả

any suggestion please ?

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 25
18
1
thg 10 20
3305
2
thg 3 15
6809
0
thg 3 15
3766
1
thg 3 15
3686