Odoo Help

Welcome!

This community 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.

0

How to calculate "Subtotal" value in purchase order form

By
Md. Shah Jalal
on 7/22/13, 2:59 PM 3,028 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

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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