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. 40
      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).
{
'name': 'Variable quantity in contract recurrent invoicing',
'version': '11.0.1.0.0',
'version': '11.0.1.1.0',
'category': 'Contract Management',
'license': 'AGPL-3',
'author': "Tecnativa,"

40
contract_variable_quantity/i18n/es.po

@ -1,22 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * contract_variable_quantity
#
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\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: es\n"
"MIME-Version: 1.0\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"
"X-Generator: Poedit 1.8.7.1\n"
#. module: contract_variable_quantity
#: 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
#: 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
#: 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"
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
#: model:ir.model.fields,field_description:contract_variable_quantity.field_contract_line_qty_formula___last_update
msgid "Last Modified on"
@ -169,6 +173,12 @@ msgstr "Formula ctdad."
msgid "Qty. type"
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
#: selection:account.analytic.contract.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
#: 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
#: 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).
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

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).
import odoo.tests
@ -58,3 +59,12 @@ class TestContractVariableQuantity(odoo.tests.HttpCase):
invoice = self.env['account.invoice'].search(
[('contract_id', '=', self.contract.id)])
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="inherit_id" ref="contract.account_analytic_account_recurring_form_form"/>
<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">
<field name="qty_type"/>
</xpath>

Loading…
Cancel
Save