Files
contract/contract/wizards/contract_manually_create_invoice.py
sbejaoui 946f2e2d48 [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.

[12.0][IMP] - log the manual invoice action in contract chatter

[IMP] - Add alink to the invoice in contract message at manual invoicing

[IMP] - Improve code

[FIX] - log message for invoice creation only when there is an invoice

[IMP] - split the manual invoice menu into to menus sale & purhcase

[IMP] - hide invoice button if there is nothing to invoice
2023-03-15 12:38:33 +01:00

67 lines
2.3 KiB
Python

# 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.TransientModel):
_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_ids"
)
contract_to_invoice_ids = fields.Many2many(
comodel_name="contract.contract",
compute="_compute_contract_to_invoice_ids",
)
contract_type = fields.Selection(
selection=[('sale', 'Customer'), ('purchase', 'Supplier')],
default='sale',
required=True,
)
@api.depends('invoice_date')
def _compute_contract_to_invoice_ids(self):
if not self.invoice_date:
# trick to show no invoice when no date has been entered yet
contract_to_invoice_domain = [('id', '=', False)]
else:
contract_to_invoice_domain = self.env[
'contract.contract'
]._get_contracts_to_invoice_domain(self.invoice_date)
self.contract_to_invoice_ids = self.env['contract.contract'].search(
contract_to_invoice_domain
+ [('contract_type', '=', self.contract_type)]
)
self.contract_to_invoice_count = len(self.contract_to_invoice_ids)
@api.multi
def action_show_contract_to_invoice(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"name": _("Contracts to invoice"),
"res_model": "contract.contract",
"domain": [('id', 'in', self.contract_to_invoice_ids.ids)],
"view_mode": "tree,form",
"context": self.env.context,
}
@api.multi
def create_invoice(self):
self.ensure_one()
invoices = self.env['account.invoice']
for contract in self.contract_to_invoice_ids:
invoices |= contract.recurring_create_invoice()
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,
}