0
votes

I'm trying to code on module.

but i'm stuck. it doesn't work.

Python code

class PurchaseCurrency(models.Model):
    _inherit = "purchase.order.line"

    new_currency = fields.Float(string="Test")

my xml

<record id="new_currency_line" model="ir.ui.view">
        <field name="name">purchase.order.form</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='order_line']/tree/field[@name='product_qty']" position="after">
                <field name="new_currency"/>
            </xpath>
        </field>
</record>

and error warning

ValueError: Field new_currency does not exist

Error context: View purchase.order.form [view_id: 1074, xml_id: purchase.purchase_order_form, model: purchase.order, parent_id: n/a]

anyone can help me?

1
Did you import your python files and restarted Odoo?CZoellner
i did it alreadyzzob
Can you please add all Errors of you server log here? Maybe there is another Error or the log that will show other things you might not have seen.CZoellner
ValueError: Field new_currency does not exist Error context: View purchase.order.form [view_id: 1074, xml_id: purchase.purchase_order_form, model: purchase.order, parent_id: n/a]zzob
Can you please check if the field is in the database for table purchase_order_line? That really is very weird. I don't see a mistake in the provided code. It has to be in code you haven't provided yet.CZoellner

1 Answers

-1
votes

Add your python model file to __init__.py from . import model

Make sure your python model directory is imported in modules root __init__.py from . import models

Restart your odoo instance and update the module from web backend or using -u module_name from command line.

You can simplify xpath expression by using field tag

<record id="new_currency_line" model="ir.ui.view">
    <field name="name">purchase.order.form.new</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form" />
    <field name="arch" type="xml">
    <field name="product_qty" position="after">
        <field name="new_currency" />
    </field>
</record>