0
votes

I have a product called "Coupon" with negative amount which is used to offset the product price. However, it seems like Odoo 8 does not allow computation of negative amount to price_subtotal (it becomes 0.00):

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

When I remove the negative sign, it computes

Coupon ... ... 1 Each  40.0000 40.0000

From an accounting perspective, the total invoice should not be negative. That stays true. However, I do need to allow negative computation of invoice line item(s). Where and what do I need to change? I tried looking into account/account.py but to no avail so far - it's all just "tax" related.

Thanks in advance!

Details of the amount column for the line total Details of the Amount column for the line total

enter image description here

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
1
Have you tried look into account_invoice.py? - SDBot
Thanks @SDBot trying to trace but can't seem to find anything that restricts the amount to 0 if price_unit is of negative value yet.... help? - jeszy
Activate developer mode (top right, click on about odoo), find out which model that field belong to, it's most likely is a computed field, look into the computed field's method if you can't find anything there, try post the method here. - SDBot
@CZoellner runbot.odoo.com helped a great deal! I didn't realize that it was a piece of the custom code that was doing the restriction - kept thinking it was from Odoo 8 itself. - jeszy
@CZoellner It was done by my predecessor :) That said, what I did was to add a level of condition prior to the customized conditions to ensure that it is not of the specific product and that the value is not negative. Worked like a charm. Thank you for pointing out runbot.odoo.com! - jeszy

1 Answers

0
votes

Odoo's default behaviour is handling it as expected. The problem is custom code. (For more information read the questions comments)