Odoo Help

0

How to calculate "Subtotal" value in purchase order form

By
Md. Shah Jalal
on 7/22/13, 2:59 PM 3,696 views

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>

0
Grover Menacho
On 7/22/13, 3:31 PM

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.

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

Md. Shah Jalal
on 7/25/13, 2:22 PM
0
Md. Shah Jalal
On 7/25/13, 2:27 PM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 7/22/13, 2:59 PM
Seen: 3696 times
Last updated: 11/30/16, 3:36 AM