Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
10429 Visualizações

I've created a module to add a new field "Shipment Cost" in the purchase order form after "unit price" field. It works successfully, but I cannot update the "subtotal" field value accordingly. the value of "Subtotal" should be (("unit price" x "Quantity") + "Shipment Cost"). Can anybody please help me? The code of the module is as below:

File 1: purchase_shipment.py

from openerp.osv import fields, osv from openerp import netsvc

class purchase_order_line(osv.osv): _name = 'purchase.order.line' _inherit = "purchase.order.line" _columns = { 'shipment_cost': fields.float('Shipment Cost', size=30, store=True), } purchase_order_line()

File 2: purchase_shipment_view.xml

<openerp> <data> <record model="ir.ui.view" id="view_purchase_form1"> <field name="name">purchase.order.form.inherit</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='price_unit']" position="after"> <field name="shipment_cost"/> </xpath> </field> </record> </data> </openerp>

Avatar
Cancelar

hello you are found any solution related this problem ??

Melhor resposta

Subtotal field is a function field. You have to override that function including your shipment cost. You will find that function before the assignment of the columns in purchase order line class.

Avatar
Cancelar
Autor

Hi, thank you for ur reply. I found that the field "Subtotal" is calculated using the function "_amount_line" in the original module. below is the code of the function def _amount_line(self, cr, uid, ids, prop, arg, context=None): res = {} cur_obj=self.pool.get('res.currency') tax_obj = self.pool.get('account.tax') for line in self.browse(cr, uid, ids, context=context): taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, line.order_id.partner_id) cur = line.order_id.pricelist_id.curr

Autor Melhor resposta

Hi, thank you for ur reply. I found that the field "Subtotal" is calculated using the function "_amount_line" in the original module. the code of the function is

def _amount_line(self, cr, uid, ids, prop, arg, context=None): res = {} cur_obj=self.pool.get('res.currency') tax_obj = self.pool.get('account.tax') for line in self.browse(cr, uid, ids, context=context): taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, line.order_id.partner_id) cur = line.order_id.pricelist_id.currency_id res[line.id] = cur_obj.round(cr, uid, cur, taxes['total']) return res

but I cannot understand how can I override this method.

Avatar
Cancelar