Odoo Help


cuold you guy please help me to show step by step to add a funcision or add an auto caculation into a exict field on the odoo 9 system?

on 8/16/16, 10:35 PM 289 views

Hi, i am new with odoo program, i would like to know all the steps to add the following code into class SaleLine that will be showed at the end.

this is the funsicion:

@api.depends('lng', 'quantity_extra')


def _compute_prodcut_uom_qty(self):

for line in self:

if line.lng:

line.quantity_product_uom_qty = line.lng  * line.quantity_extra

and how can i add the funcision into this class of module? im using odoo 9

class SaleLine(models.Model):

_inherit = "sale.order.line"

width_id = fields.Many2one('sale.order.line.width', u'Ki��^�u tính')

lng = fields.Float(u'Dài', default=1)

formula = fields.Char(compute='_get_formula', string=u'Công thức')

unit_id = fields.Many2one('product.uom', string=u'�^�ơn v��^�')

quantity_extra = fields.Float(u'Tấm', default=1)

quantity_sum = fields.Float(compute='_compute_quantity', string=u'S��^� lượng m��^� r��^�ng', store=True)

is_copy = fields.Boolean('Is Copy')

@api.depends('width_id', 'lng', 'quantity_extra')


def _compute_quantity(self):

for line in self:

if line.width_id:

line.quantity_sum = line.lng * line.width_id.rate * line.quantity_extra


def _onchange_component_sale_line(self):

if self.width_id:

self.unit_id = self.width_id.unit_id.id


def _get_formula(self):

for order_line in self:

if order_line.width_id:

if order_line.width_id.rate == 1 or not order_line.width_id:

order_line.formula = ''


order_line.formula = '%s x %s x %s x %s' % (order_line.width_id.rate, order_line.lng, order_line.quantity_extra, '{:20,.2f}'.format(order_line.price_$

@api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id', 'width_id', 'lng', 'quantity_extra')

def _compute_amount(self):

res = super(SaleLine, self)._compute_amount()

for line in self:

if line.width_id:

line.price_total = line.lng * line.width_id.rate * line.quantity_extra * line.price_unit

line.price_subtotal = line.lng * line.width_id.rate * line.quantity_extra * line.price_unit

return res


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.


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

2 follower(s)


Asked: 8/16/16, 10:35 PM
Seen: 289 times
Last updated: 8/17/16, 4:23 AM