This question has been flagged
3130 Views

Hi,

I've got a simple question which I didn't find in a couple of threads.

I'm modifying the on_change method of the pricelist field belonging to the purchase module. The pricelist field should always actualize the prices of all order_line product entries when the pricelist itself has been changed. For this purpose, it is necessary to read all "price_unit" fields belonging to the one2many field "order_line". The fields are inside the purchase form view (purchase_order_form). The problem is that I can't read the fields belonging to the order_line directly (maybe because they reside in purchase.order.line and not in purchase.order)
What I tried:
I added order line as a parameter for the onchange_pricelist method (both in the view and python coden) and debugged the variable order_line: It is not giving any information of the order lines!
Maybe it is not possible to read the order_lines dynamically without storing them into the database? Maybe only dynamically updating works?
>>Does somebody have a solution how I can read the price_unit dynamically?<<

I copied a fragment of the purchase_order_form view, so you can look up the view structure at once.

<record id="purchase_order_form" model="ir.ui.view">
            ...
            <field name="arch" type="xml">
<group>
                        <group>
                            <field name="partner_id" on_change="onchange_partner_id(partner_id, context)" context="{'search_default_supplier':1, 'default_supplier':1, 'default_customer':0}" domain="[('supplier','=',True)]"/>
                            <field name="partner_ref"/>
                            <field domain="[('type','=','purchase')]" name="pricelist_id" groups="product.group_purchase_pricelist" on_change="onchange_pricelist(pricelist_id, context)"/>
                            <field name="currency_id" groups="base.group_multi_currency"/>
                            <field name="journal_id" invisible='1'/>
                        </group>
                        <group>
                            <field name="date_order"/>
                            <field name="origin" attrs="{'invisible': [('origin','=',False)]}"/>
                            <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                            <field name="picking_type_id" on_change="onchange_picking_type_id(picking_type_id, context)" domain="[('code','=','incoming')]" widget="selection" context="{'special_shortened_wh_name': True}" groups="stock.group_locations"/>
                            <field name="related_location_id" invisible="1"/>
                            <field name="dest_address_id" string="Customer Address" on_change="onchange_dest_address_id(dest_address_id, context)"
                                attrs="{'invisible':['|', ('picking_type_id','=',False), ('related_location_id','!=', False)],
                                'required': [('picking_type_id','!=',False), ('related_location_id','=', False)]}"
                                groups="stock.group_locations"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Products">
                            <field name="order_line"> <!-- HERE IS order_line  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
                                <tree string="Purchase Order Lines" editable="bottom">
                                    <field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,False,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,False,parent.state,context)"/>
                                    <field name="name"/>
                                    <field name="date_planned"/>
                                    <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                                    <field name="account_analytic_id" groups="purchase.group_analytic_accounting" domain="[('type','not in',('view','template'))]"/>
                                    <field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,parent.state,context)"/>
                                    <field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,parent.state,context)"/>
                                    <field name="price_unit"/>
                                    <field name="taxes_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
                                    <field name="price_subtotal"/>
                                    <field name="state" invisible="1"/>
                                </tree>
                            </field>

Avatar
Discard