Skip to Content
Menu
This question has been flagged
1731 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

 



Avatar
Discard