Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
5119 Widoki

I allready made a modul to create field base_price at sales order line, now I want to fill that field with list_price from product template and change everytime product_id change, how to write a modul for that purpose.

I wrote this modul for trial , but didn't work.

this is modul to create field base_price

from openerp.osv import orm, fields

import openerp.addons.decimal_precision as dp

class sale_order_line(orm.Model):

_name = 'sale.order.line'

_inherit = 'sale.order.line'

_columns = {

'base_price':fields.float('Base Price', required=True, digits_compute=dp.get_precision('Product Price'), readonly=True, states={'draft':[('readonly', False)]}),

}

_default = {

'base_price': 0.0,

}

this is the xml file

<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/form/group/group/field[@name='price_unit' ]" position="before">
<field name="base_price"/>
</xpath>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit' ]" position="before">
<field name="base_price"/>
</xpath>
</field>
</record>
</data>
</openerp>

And this is a modul to fiiling value to that fields, and I make it at different modul.

from openerp.osv import orm, fields, api

class sale_order_line(orm.Model):

    _inherit = "sale.order.line"

    def product_id_change( self, cr, uid, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='',

        partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False,

        fiscal_position=False, flag=False, context=None):

        

        vals=super(sale_order_line.self).product_id_change(cr, uid, ids, pricelist, product, qty=qty, uom=uom,

        qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax,         date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

        vals['value'].update({'base_price':999.99})

        return vals

There are no error when I'm installing this modul, but when I change Product at sales order line form, nothing happened to field base_price.

Sorry there are no equal before 999.99, it's mistype.


Awatar
Odrzuć
Autor

@Goswani : Sorry, it's not worked, nothing change. thanks

Try to change this line without "equal to"(=) symbol in it vals['value'].update({'base_price': 999.99})

also, it would be helpful if you provide us with the error traceback in the question itself by editing it.

Najlepsza odpowiedź

Rudyanto,

First of all as you said "I allready made a modul to create field base_price at sales order line", i can't see any defination of creating "base_price" field in your module!!. so, please add it if you missed.....

Second, there is no need of "_name" attribute, it will create a new object with sale.order.line and you will not have any access to the methods of previous one, for that please try to print "vals" to see if you are getting any values returned in "vals" varialble after calling super. Please remove "_name" attribute, "_inherit" only is enough for the purpose.

Hope this will help you...

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
maj 24
5974
1
sty 20
5719
2
lip 17
7022
1
sty 16
3267
0
wrz 15
3608