mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract_variable_quantity: Add option to don't create zero qty invoice lines
This commit is contained in:
committed by
Víctor Martínez
parent
ba19f264fa
commit
0a40701461
@@ -1,13 +1,20 @@
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2016 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2018 Tecnativa - Carlos Dauden
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models, exceptions
|
||||
from odoo.tools import float_is_zero
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class AccountAnalyticAccount(models.Model):
|
||||
_inherit = "account.analytic.account"
|
||||
|
||||
skip_zero_qty = fields.Boolean(
|
||||
string='Skip Zero Qty Lines',
|
||||
help="If checked, contract lines with 0 qty don't create invoice line",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _prepare_invoice_line(self, line, invoice_id):
|
||||
vals = super(AccountAnalyticAccount, self)._prepare_invoice_line(
|
||||
@@ -23,7 +30,14 @@ class AccountAnalyticAccount(models.Model):
|
||||
}
|
||||
safe_eval(line.qty_formula_id.code.strip(), eval_context,
|
||||
mode="exec", nocopy=True) # nocopy for returning result
|
||||
vals['quantity'] = eval_context.get('result', 0)
|
||||
qty = eval_context.get('result', 0)
|
||||
if self.skip_zero_qty and float_is_zero(
|
||||
qty, self.env['decimal.precision'].precision_get(
|
||||
'Product Unit of Measure')):
|
||||
# Return empty dict to skip line create
|
||||
vals = {}
|
||||
else:
|
||||
vals['quantity'] = qty
|
||||
return vals
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user