Why am I not getting the same calculation result in invoice line as in sale order line?
When I'm confirming the sale order, it gives me a correct calculation result in invoice line, but as I separately create it from invoice line, it gives me a different calculation result. Below is my code.
What else can I do in account_invoice_line.py file?
class account_invoice_line(models.Model):
_inherit = 'account.invoice.line'
def _make_invoice(self, cr, uid, order, lines, context=None):
inv_id = super(sale_order_line, self)._make_invoice(cr, uid, order, lines, context)
inv_obj = self.pool.get('account.invoice.line')
if order.name_of_your_field:
inv_obj.write(cr, uid, [inv_id], {'order_line': order_line.id}, context=context)
return inv_id
# _columns = {
qty_char = fields.Float('Qty in M. Sqr')
def on_change_qty_squ(self, cr, uid, ids, qty_char, product , price_unit=0 , quantity=0 ,price_after_discount=0 , context=None):
qty_char = qty_char
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context)
prod_type = product_obj.supp_ref
# prod_price = product_obj.lst_price
squ_meter = product_obj.squ_meter
price = price_unit
value = {}
if prod_type == 'T':
if qty_char:
typ = float(qty_char)
qty = typ / squ_meter
round = math.ceil(qty)
new_qty = round * squ_meter
value['quantity'] = round
subtotal = (quantity) * (price_after_discount)
value['price_subtotal'] = subtotal
else:
if qty_char:
typ = float(qty_char)
qty = typ / squ_meter
round = math.ceil(qty)
new_qty = round * squ_meter
value['quantity'] = round
subtotal = (quantity) * (price_after_discount)
value['price_subtotal'] = subtotal
return {'value': value}
@api.depends('price_after', 'price_unit', 'discount', 'invoice_line_tax_id', 'quantity',
'qty_char','product_id', 'invoice_id.partner_id', 'invoice_id.discount', 'invoice_id.currency_id', 'invoice_id.company_id')
def _compute_price_after(self):
self.price_after = self.price_unit * (1 - (self.invoice_id.discount or 0.0) / 100.0)
price_after = fields.Float(string='Price After Discount', digits= dp.get_precision('Account'),
store=True, readonly=True, compute='_compute_price_after')