[ADD] contract_variable_quantity:

=================================================
Variable quantity in contract recurrent invoicing
=================================================

With this module, you will be able to define in recurring contracts some
lines with variable quantity according a provided formula.

Configuration
=============

* Go to Sales > Configuration > Contracts > Formulas (quantity).
* Define any formula based on Python code that stores at some moment a
  float/integer value of the quantity to invoice in the variable 'result'.

  You can use these variables to compute your formula:

  * *env*: Environment variable for getting other models.
  * *context*: Current context dictionary.
  * *user*: Current user.
  * *line*: Contract recurring invoice line that triggers this formula.
  * *contract*: Contract whose line belongs to.
  * *invoice*: Invoice (header) being created.

Usage
=====

To use this module, you need to:

* Go to Sales -> Contracts and select or create a new contract.
* Check *Generate recurring invoices automatically*.
* Add a new recurring invoicing line.
* Select "Variable quantity" in column "Qty. type".
* Select one of the possible formulas to use (previously created).
This commit is contained in:
Pedro M. Baeza
2016-09-09 03:03:38 +02:00
committed by Carlos Roca
parent 9652c7613a
commit e026e60fb8
11 changed files with 625 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_analytic_account_recurring_form_form" model="ir.ui.view">
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="contract.account_analytic_account_recurring_form_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='recurring_invoice_line_ids']//field[@name='quantity']" position="before">
<field name="qty_type"/>
</xpath>
<xpath expr="//field[@name='recurring_invoice_line_ids']//field[@name='quantity']" position="after">
<field name="qty_formula_id"
attrs="{'required': [('qty_type', '=', 'variable')], 'invisible': [('qty_type', '!=', 'variable')]}"
/>
</xpath>
<xpath expr="//field[@name='recurring_invoice_line_ids']//field[@name='quantity']" position="attributes">
<attribute name="attrs">{'required': [('qty_type', '=', 'fixed')], 'invisible': [('qty_type', '!=', 'fixed')]}</attribute>
</xpath>
</field>
</record>
<record id="view_contract_line_qty_formula_tree" model="ir.ui.view">
<field name="model">contract.line.qty.formula</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
</tree>
</field>
</record>
<record id="view_contract_line_qty_formula_form" model="ir.ui.view">
<field name="model">contract.line.qty.formula</field>
<field name="arch" type="xml">
<form >
<sheet>
<div class="oe_title">
<h1>
<field name="name" placeholder="Name"/>
</h1>
</div>
<group string="Code">
<div style="margin-top: 4px;">
<field name="code" nolabel="1"/>
<h3>Help with Python expressions.</h3>
<p>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'.</p>
<p>You can use these variables to compute your formula:</p>
<ul>
<li><i>env</i>: Environment variable for getting other models.</li>
<li><i>context</i>: Current context dictionary.</li>
<li><i>user</i>: Current user.</li>
<li><i>line</i>: Contract recurring invoice line that triggers this formula.</li>
<li><i>contract</i>: Contract whose line belongs to.</li>
<li><i>invoice</i>: Invoice (header) being created.</li>
</ul>
<div>
<p>Example of Python code</p>
<code>
result = env['product.product'].search_count([('sale_ok', '=', True)])
</code>
</div>
</div>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_contract_quantity_formula" model="ir.actions.act_window">
<field name="name">Formulas (quantity)</field>
<field name="res_model">contract.line.qty.formula</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new formula for variable quantities.
</p>
</field>
</record>
<menuitem id="contract.menu_config_contract"
name="Contracts"
sequence="5"
parent="base.menu_sale_config"
/>
<menuitem id="menu_contract_quantity_formula"
action="action_contract_quantity_formula"
parent="contract.menu_config_contract"
/>
</odoo>