Odoo 8 允许负发票行项目

Odoo 8 Allow Negative Invoice Line Item

我有一个名为 "Coupon" 的产品,其金额为负数,用于抵消产品价格。但是,Odoo 8 似乎不允许计算负数 price_subtotal(变为 0.00):

Coupon ... ... 1 Each -40.0000 0.0000

当我删除负号时,它会计算

Coupon ... ... 1 Each  40.0000 40.0000

从会计的角度来看,发票总额不应该是负数。那是真的。但是,我确实需要允许对发票行项目进行负计算。 我需要在哪里更改什么?我尝试查看 account/account.py 但到目前为止无济于事 - 这只是 "tax" 相关。

提前致谢!

行合计金额栏的详细信息

class account_invoice(models.Model)
    ....

    @api.one
    @api.depends('invoice_line.price_subtotal', 'tax_line.amount')
    def _compute_amount(self):
        self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line)
        self.amount_tax = sum(line.amount for line in self.tax_line)
        self.amount_total = self.amount_untaxed + self.amount_tax

    ....

class account_invoice_line(models.Model):
    _name = "account.invoice.line"
    _description = "Invoice Line"
    _order = "invoice_id,sequence,id"

    @api.one
    @api.depends('price_unit', 'discount', 'invoice_line_tax_id', 'quantity',
        'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id')
    def _compute_price(self):
        price = self.price_unit * (1 - (self.discount or 0.0) / 100.0)
        taxes = self.invoice_line_tax_id.compute_all(price, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id)
        self.price_subtotal = taxes['total']
        if self.invoice_id:
            self.price_subtotal = self.invoice_id.currency_id.round(self.price_subtotal)

    @api.model
    def _default_price_unit(self):
        if not self._context.get('check_total'):
            return 0
        total = self._context['check_total']
        for l in self._context.get('invoice_line', []):
            if isinstance(l, (list, tuple)) and len(l) >= 3 and l[2]:
                vals = l[2]
                price = vals.get('price_unit', 0) * (1 - vals.get('discount', 0) / 100.0)
                total = total - (price * vals.get('quantity'))
                taxes = vals.get('invoice_line_tax_id')
                if taxes and len(taxes[0]) >= 3 and taxes[0][2]:
                    taxes = self.env['account.tax'].browse(taxes[0][2])
                    tax_res = taxes.compute_all(price, vals.get('quantity'),
                        product=vals.get('product_id'), partner=self._context.get('partner_id'))
                    for tax in tax_res['taxes']:
                        total = total - tax['amount']
        return total

Odoo 的默认行为是按预期处理它。问题是自定义代码。 (有关更多信息,请阅读问题评论)