如何在发票行和在odoo中的销售订单行中得到正确的计算结果?

2024-03-29 15:43:21 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么发票行和销售订单行的计算结果不一样?在

当我确认销售订单时,它会在invoice line中给我一个正确的计算结果,但是由于我是从invoice line中单独创建它,它会给我一个不同的计算结果。下面是我的代码。在

我还能在账户发票上做什么_行.py文件?在

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

Tags: selfidobjvaluecontextlineorderinvoice