mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract_variable_quantity: black, isort, prettier
This commit is contained in:
committed by
Carolina Fernandez
parent
ee541c0faa
commit
ee16520039
@@ -7,15 +7,12 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class ContractAbstractContractLine(models.AbstractModel):
|
||||
_inherit = 'contract.abstract.contract.line'
|
||||
_inherit = "contract.abstract.contract.line"
|
||||
|
||||
qty_type = fields.Selection(
|
||||
selection=[
|
||||
('fixed', 'Fixed quantity'),
|
||||
('variable', 'Variable quantity'),
|
||||
],
|
||||
selection=[("fixed", "Fixed quantity"), ("variable", "Variable quantity")],
|
||||
required=True,
|
||||
default='fixed',
|
||||
default="fixed",
|
||||
string="Qty. type",
|
||||
)
|
||||
qty_formula_id = fields.Many2one(
|
||||
|
||||
@@ -10,6 +10,6 @@ class ContractContract(models.Model):
|
||||
_inherit = "contract.contract"
|
||||
|
||||
skip_zero_qty = fields.Boolean(
|
||||
string='Skip Zero Qty Lines',
|
||||
string="Skip Zero Qty Lines",
|
||||
help="If checked, contract lines with 0 qty don't create invoice line",
|
||||
)
|
||||
|
||||
@@ -9,30 +9,28 @@ from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class AccountAnalyticInvoiceLine(models.Model):
|
||||
_inherit = 'contract.line'
|
||||
_inherit = "contract.line"
|
||||
|
||||
@api.multi
|
||||
def _get_quantity_to_invoice(
|
||||
self, period_first_date, period_last_date, invoice_date
|
||||
):
|
||||
quantity = super(
|
||||
AccountAnalyticInvoiceLine, self
|
||||
)._get_quantity_to_invoice(
|
||||
quantity = super(AccountAnalyticInvoiceLine, self)._get_quantity_to_invoice(
|
||||
period_first_date, period_last_date, invoice_date
|
||||
)
|
||||
if not period_first_date or not period_last_date or not invoice_date:
|
||||
return quantity
|
||||
if self.qty_type == 'variable':
|
||||
if self.qty_type == "variable":
|
||||
eval_context = {
|
||||
'env': self.env,
|
||||
'context': self.env.context,
|
||||
'user': self.env.user,
|
||||
'line': self,
|
||||
'quantity': quantity,
|
||||
'period_first_date': period_first_date,
|
||||
'period_last_date': period_last_date,
|
||||
'invoice_date': invoice_date,
|
||||
'contract': self.contract_id,
|
||||
"env": self.env,
|
||||
"context": self.env.context,
|
||||
"user": self.env.user,
|
||||
"line": self,
|
||||
"quantity": quantity,
|
||||
"period_first_date": period_first_date,
|
||||
"period_last_date": period_last_date,
|
||||
"invoice_date": invoice_date,
|
||||
"contract": self.contract_id,
|
||||
}
|
||||
safe_eval(
|
||||
self.qty_formula_id.code.strip(),
|
||||
@@ -40,7 +38,7 @@ class AccountAnalyticInvoiceLine(models.Model):
|
||||
mode="exec",
|
||||
nocopy=True,
|
||||
) # nocopy for returning result
|
||||
quantity = eval_context.get('result', 0)
|
||||
quantity = eval_context.get("result", 0)
|
||||
return quantity
|
||||
|
||||
@api.multi
|
||||
@@ -49,13 +47,11 @@ class AccountAnalyticInvoiceLine(models.Model):
|
||||
invoice_id=invoice_id, invoice_values=invoice_values,
|
||||
)
|
||||
if (
|
||||
'quantity' in vals
|
||||
"quantity" in vals
|
||||
and self.contract_id.skip_zero_qty
|
||||
and float_is_zero(
|
||||
vals['quantity'],
|
||||
self.env['decimal.precision'].precision_get(
|
||||
'Product Unit of Measure'
|
||||
),
|
||||
vals["quantity"],
|
||||
self.env["decimal.precision"].precision_get("Product Unit of Measure"),
|
||||
)
|
||||
):
|
||||
vals = {}
|
||||
|
||||
@@ -3,38 +3,36 @@
|
||||
# Copyright 2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models, exceptions
|
||||
from odoo import _, api, exceptions, fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class ContractLineFormula(models.Model):
|
||||
_name = 'contract.line.qty.formula'
|
||||
_description = 'Contract Line Formula'
|
||||
_name = "contract.line.qty.formula"
|
||||
_description = "Contract Line Formula"
|
||||
|
||||
name = fields.Char(required=True, translate=True)
|
||||
code = fields.Text(required=True, default="result = 0")
|
||||
|
||||
@api.constrains('code')
|
||||
@api.constrains("code")
|
||||
def _check_code(self):
|
||||
eval_context = {
|
||||
'env': self.env,
|
||||
'context': self.env.context,
|
||||
'user': self.env.user,
|
||||
'line': self.env['contract.line'],
|
||||
'contract': self.env['contract.contract'],
|
||||
'invoice': self.env['account.invoice'],
|
||||
'quantity': 0,
|
||||
'period_first_date': False,
|
||||
'period_last_date': False,
|
||||
'invoice_date': False,
|
||||
"env": self.env,
|
||||
"context": self.env.context,
|
||||
"user": self.env.user,
|
||||
"line": self.env["contract.line"],
|
||||
"contract": self.env["contract.contract"],
|
||||
"invoice": self.env["account.invoice"],
|
||||
"quantity": 0,
|
||||
"period_first_date": False,
|
||||
"period_last_date": False,
|
||||
"invoice_date": False,
|
||||
}
|
||||
try:
|
||||
safe_eval(
|
||||
self.code.strip(), eval_context, mode="exec", nocopy=True
|
||||
)
|
||||
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True)
|
||||
except Exception as e:
|
||||
raise exceptions.ValidationError(
|
||||
_('Error evaluating code.\nDetails: %s') % e
|
||||
_("Error evaluating code.\nDetails: %s") % e
|
||||
)
|
||||
if 'result' not in eval_context:
|
||||
raise exceptions.ValidationError(_('No valid result returned.'))
|
||||
if "result" not in eval_context:
|
||||
raise exceptions.ValidationError(_("No valid result returned."))
|
||||
|
||||
Reference in New Issue
Block a user