Browse Source
[12.0][IMP] - Add an action for contracts manual invoicing
[12.0][IMP] - Add an action for contracts manual invoicing
It happen that a company has to trigger the invoicing action to generate invoices before the scheduled date (to print and prepare invoices documents, check invoices, etc.). This requires technical access for end users with the risk that this represents. This commit adds a new wizard to run the invoicing action for a given date with a helper to see and check the contract that will be invoiced. When the manual action is called, the system displays all created invoices.pull/414/head
sbejaoui
5 years ago
7 changed files with 161 additions and 4 deletions
-
1contract/__manifest__.py
-
9contract/models/contract.py
-
1contract/security/ir.model.access.csv
-
33contract/tests/test_contract.py
-
1contract/wizards/__init__.py
-
62contract/wizards/contract_manually_create_invoice.py
-
58contract/wizards/contract_manually_create_invoice.xml
@ -1 +1,2 @@ |
|||||
from . import contract_line_wizard |
from . import contract_line_wizard |
||||
|
from . import contract_manually_create_invoice |
@ -0,0 +1,62 @@ |
|||||
|
# Copyright 2019 ACSONE SA/NV |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
|
||||
|
class ContractManuallyCreateInvoice(models.Model): |
||||
|
|
||||
|
_name = 'contract.manually.create.invoice' |
||||
|
_description = 'Contract Manually Create Invoice Wizard' |
||||
|
|
||||
|
invoice_date = fields.Date(string="Invoice Date", required=True) |
||||
|
contract_to_invoice_count = fields.Integer( |
||||
|
compute="_compute_contract_to_invoice_count" |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
def action_show_contract_to_invoice(self): |
||||
|
self.ensure_one() |
||||
|
if not self.invoice_date: |
||||
|
contract_to_invoice_domain = [('id', '=', False)] |
||||
|
else: |
||||
|
contract_to_invoice_domain = self.env[ |
||||
|
'contract.contract' |
||||
|
]._get_contracts_to_invoice_domain(self.invoice_date) |
||||
|
|
||||
|
return { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"name": _("Contracts to invoice"), |
||||
|
"res_model": "contract.contract", |
||||
|
"domain": contract_to_invoice_domain, |
||||
|
"view_mode": "tree,form", |
||||
|
"context": self.env.context, |
||||
|
} |
||||
|
|
||||
|
@api.depends('invoice_date') |
||||
|
def _compute_contract_to_invoice_count(self): |
||||
|
self.ensure_one() |
||||
|
if not self.invoice_date: |
||||
|
self.contract_to_invoice_count = 0 |
||||
|
else: |
||||
|
contract_model = self.env['contract.contract'] |
||||
|
self.contract_to_invoice_count = contract_model.search_count( |
||||
|
contract_model._get_contracts_to_invoice_domain( |
||||
|
self.invoice_date |
||||
|
) |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
def create_invoice(self): |
||||
|
self.ensure_one() |
||||
|
invoices = self.env['contract.contract'].cron_recurring_create_invoice( |
||||
|
self.invoice_date |
||||
|
) |
||||
|
return { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"name": _("Invoices"), |
||||
|
"res_model": "account.invoice", |
||||
|
"domain": [('id', 'in', invoices.ids)], |
||||
|
"view_mode": "tree,form", |
||||
|
"context": self.env.context, |
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- Copyright 2019 ACSONE SA/NV |
||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
||||
|
|
||||
|
<odoo> |
||||
|
|
||||
|
<record model="ir.ui.view" id="contract_manually_create_invoice_form_view"> |
||||
|
<field name="model">contract.manually.create.invoice</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Contract Manually Create Invoice"> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="invoice_date"/> |
||||
|
</group> |
||||
|
<group> |
||||
|
<button name="action_show_contract_to_invoice" type="object" |
||||
|
class="btn-link" |
||||
|
attrs="{'invisible': [('contract_to_invoice_count', '=', 0)]}"> |
||||
|
<field name="contract_to_invoice_count"/> |
||||
|
<span attrs="{'invisible': [('contract_to_invoice_count', '>', 1)]}"> |
||||
|
contract to invoice |
||||
|
</span> |
||||
|
<span attrs="{'invisible': [('contract_to_invoice_count', '<', 1)]}"> |
||||
|
contracts to invoice |
||||
|
</span> |
||||
|
</button> |
||||
|
</group> |
||||
|
</group> |
||||
|
<footer> |
||||
|
<button name="create_invoice" |
||||
|
string="Create Invoices" |
||||
|
class="btn-primary" |
||||
|
type="object"/> |
||||
|
<button string="Cancel" |
||||
|
class="btn-default" |
||||
|
special="cancel"/> |
||||
|
</footer> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.actions.act_window" |
||||
|
id="contract_manually_create_invoice_act_window"> |
||||
|
<field name="name">Manually Invoice Contracts</field> |
||||
|
<field name="res_model">contract.manually.create.invoice</field> |
||||
|
<field name="view_mode">form</field> |
||||
|
<field name="context">{}</field> |
||||
|
<field name="target">new</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.ui.menu" id="contract_manually_create_invoice_menu"> |
||||
|
<field name="name">Manually Invoice Contracts</field> |
||||
|
<field name="parent_id" ref="account.menu_finance"/> |
||||
|
<field name="action" |
||||
|
ref="contract_manually_create_invoice_act_window"/> |
||||
|
<field name="sequence" eval="16"/> |
||||
|
</record> |
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue