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

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?

By
thanhthuansteel
on 8/16/16, 10:35 PM 77 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')

@api.multi

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')

@api.multi

def _compute_quantity(self):

for line in self:

if line.width_id:

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

@api.onchange('width_id')

def _onchange_component_sale_line(self):

if self.width_id:

self.unit_id = self.width_id.unit_id.id

@api.multi

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 = ''

else:

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

 



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

2 follower(s)

Stats

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