Browse Source

[IMP] contract_variable_quantity: Add option to don't create zero qty invoice lines

pull/238/head
Carlos Dauden 7 years ago
committed by sbejaoui
parent
commit
37066dbb47
  1. 5
      contract_variable_quantity/__manifest__.py
  2. 38
      contract_variable_quantity/i18n/es.po
  3. 18
      contract_variable_quantity/models/contract.py
  4. 12
      contract_variable_quantity/tests/test_contract_variable_quantity.py
  5. 3
      contract_variable_quantity/views/contract_view.xml

5
contract_variable_quantity/__manifest__.py

@ -1,9 +1,10 @@
# © 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Variable quantity in contract recurrent invoicing', 'name': 'Variable quantity in contract recurrent invoicing',
'version': '11.0.1.0.0',
'version': '11.0.1.1.0',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "Tecnativa," 'author': "Tecnativa,"

38
contract_variable_quantity/i18n/es.po

@ -8,15 +8,16 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 11.0\n" "Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-17 13:50+0000\n"
"PO-Revision-Date: 2018-01-17 13:50+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2018\n"
"POT-Creation-Date: 2018-03-27 14:42+0200\n"
"PO-Revision-Date: 2018-03-27 14:44+0200\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" "Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.7.1\n"
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form #: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form
@ -51,11 +52,8 @@ msgstr "<i>invoice</i>: Factura (cabecera) siendo creada."
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form #: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form
msgid ""
"<i>line</i>: Contract recurring invoice line that triggers this formula."
msgstr ""
"<i>line</i>: Línea del contrato de facturación recurrente que lanza esta "
"fórmula."
msgid "<i>line</i>: Contract recurring invoice line that triggers this formula."
msgstr "<i>line</i>: Línea del contrato de facturación recurrente que lanza esta fórmula."
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form #: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form
@ -130,6 +128,12 @@ msgstr "Ayuda con las expresiones Python."
msgid "ID" msgid "ID"
msgstr "ID (identificación)" msgstr "ID (identificación)"
#. module: contract_variable_quantity
#: model:ir.model.fields,help:contract_variable_quantity.field_account_analytic_account_skip_zero_qty
#: model:ir.model.fields,help:contract_variable_quantity.field_project_project_skip_zero_qty
msgid "If checked, contract lines with 0 qty don't create invoice line"
msgstr "Si está marcado, las lineas de contrato con cantidad 0 no crearán líneas de factura"
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.model.fields,field_description:contract_variable_quantity.field_contract_line_qty_formula___last_update #: model:ir.model.fields,field_description:contract_variable_quantity.field_contract_line_qty_formula___last_update
msgid "Last Modified on" msgid "Last Modified on"
@ -169,6 +173,12 @@ msgstr "Formula ctdad."
msgid "Qty. type" msgid "Qty. type"
msgstr "Tipo ctdad." msgstr "Tipo ctdad."
#. module: contract_variable_quantity
#: model:ir.model.fields,field_description:contract_variable_quantity.field_account_analytic_account_skip_zero_qty
#: model:ir.model.fields,field_description:contract_variable_quantity.field_project_project_skip_zero_qty
msgid "Skip Zero Qty Lines"
msgstr "Saltar líneas con cantidad 0"
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: selection:account.analytic.contract.line,qty_type:0 #: selection:account.analytic.contract.line,qty_type:0
#: selection:account.analytic.invoice.line,qty_type:0 #: selection:account.analytic.invoice.line,qty_type:0
@ -182,12 +192,8 @@ msgstr "Puede usar estas variables para calcular su fórmula:"
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form #: model:ir.ui.view,arch_db:contract_variable_quantity.view_contract_line_qty_formula_form
msgid ""
"You have to insert valid Python code block that stores at some moment a "
"float/integer value of the quantity to invoice in the variable 'result'."
msgstr ""
"Debe insertar un bloque de código Python que almacene en algún momento un "
"valor entero o decimal de la cantidad a facturar en la variable 'result'."
msgid "You have to insert valid Python code block that stores at some moment a float/integer value of the quantity to invoice in the variable 'result'."
msgstr "Debe insertar un bloque de código Python que almacene en algún momento un valor entero o decimal de la cantidad a facturar en la variable 'result'."
#. module: contract_variable_quantity #. module: contract_variable_quantity
#: model:ir.model,name:contract_variable_quantity.model_account_analytic_invoice_line #: model:ir.model,name:contract_variable_quantity.model_account_analytic_invoice_line

18
contract_variable_quantity/models/contract.py

@ -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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models, exceptions from odoo import _, api, fields, models, exceptions
from odoo.tools import float_is_zero
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
class AccountAnalyticAccount(models.Model): class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account" _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 @api.model
def _prepare_invoice_line(self, line, invoice_id): def _prepare_invoice_line(self, line, invoice_id):
vals = super(AccountAnalyticAccount, self)._prepare_invoice_line( 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, safe_eval(line.qty_formula_id.code.strip(), eval_context,
mode="exec", nocopy=True) # nocopy for returning result 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 return vals

12
contract_variable_quantity/tests/test_contract_variable_quantity.py

@ -1,4 +1,5 @@
# © 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import odoo.tests import odoo.tests
@ -58,3 +59,12 @@ class TestContractVariableQuantity(odoo.tests.HttpCase):
invoice = self.env['account.invoice'].search( invoice = self.env['account.invoice'].search(
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertEqual(invoice.invoice_line_ids[0].quantity, 12) self.assertEqual(invoice.invoice_line_ids[0].quantity, 12)
def test_check_skip_zero_qty(self):
self.formula.code = 'result=0'
self.contract.skip_zero_qty = True
invoice = self.contract._create_invoice()
self.assertFalse(invoice.invoice_line_ids)
self.contract.skip_zero_qty = False
invoice = self.contract._create_invoice()
self.assertAlmostEqual(invoice.invoice_line_ids[0].quantity, 0.0)

3
contract_variable_quantity/views/contract_view.xml

@ -24,6 +24,9 @@
<field name="model">account.analytic.account</field> <field name="model">account.analytic.account</field>
<field name="inherit_id" ref="contract.account_analytic_account_recurring_form_form"/> <field name="inherit_id" ref="contract.account_analytic_account_recurring_form_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="recurring_next_date" position="after">
<field name="skip_zero_qty"/>
</field>
<xpath expr="//field[@name='recurring_invoice_line_ids']//field[@name='quantity']" position="before"> <xpath expr="//field[@name='recurring_invoice_line_ids']//field[@name='quantity']" position="before">
<field name="qty_type"/> <field name="qty_type"/>
</xpath> </xpath>

Loading…
Cancel
Save