mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[10.0][IMP] contract. Enable automatic invoice generation before invoice date. (#282)
* [IMP] contract. Enable automatic invoice generation before invoice date. * [IMP] contract pregenerate - improvements after review.
This commit is contained in:
committed by
Rafael Blasco
parent
2337ad191c
commit
14f3cc2775
@@ -5,7 +5,7 @@
|
|||||||
# Copyright 2016-2017 Tecnativa - Carlos Dauden
|
# Copyright 2016-2017 Tecnativa - Carlos Dauden
|
||||||
# Copyright 2017 Tecnativa - Vicent Cubells
|
# Copyright 2017 Tecnativa - Vicent Cubells
|
||||||
# Copyright 2016-2017 LasLabs Inc.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Contracts Management - Recurring',
|
'name': 'Contracts Management - Recurring',
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
'views/account_analytic_contract_view.xml',
|
'views/account_analytic_contract_view.xml',
|
||||||
'views/account_invoice_view.xml',
|
'views/account_invoice_view.xml',
|
||||||
'views/res_partner_view.xml',
|
'views/res_partner_view.xml',
|
||||||
|
'views/res_company.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import account_analytic_contract
|
from . import account_analytic_contract
|
||||||
from . import account_analytic_account
|
from . import account_analytic_account
|
||||||
@@ -7,3 +7,4 @@ from . import account_analytic_contract_line
|
|||||||
from . import account_analytic_invoice_line
|
from . import account_analytic_invoice_line
|
||||||
from . import account_invoice
|
from . import account_invoice
|
||||||
from . import res_partner
|
from . import res_partner
|
||||||
|
from . import res_company
|
||||||
|
|||||||
@@ -4,15 +4,17 @@
|
|||||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||||
# Copyright 2016-2017 Carlos Dauden <carlos.dauden@tecnativa.com>
|
# Copyright 2016-2017 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||||
# Copyright 2016-2017 LasLabs Inc.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# Copyright 2018 Therp BV <https://therp.nl>.
|
# Copyright 2018-2019 Therp BV <https://therp.nl>.
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||||
|
|
||||||
|
|
||||||
class AccountAnalyticAccount(models.Model):
|
class AccountAnalyticAccount(models.Model):
|
||||||
@@ -341,13 +343,27 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def cron_recurring_create_invoice(self, limit=None):
|
def cron_recurring_create_invoice(self, limit=None):
|
||||||
today = fields.Date.today()
|
"""Generate invoices.
|
||||||
|
|
||||||
|
Invoices can be generated a specified number of days before the
|
||||||
|
invoice date, to allow the user to check the invoices before
|
||||||
|
confirmation, or to send out the invoices to the customers before
|
||||||
|
the invoice date.
|
||||||
|
"""
|
||||||
|
today = datetime.today()
|
||||||
|
company_model = self.env['res.company']
|
||||||
|
for company in company_model.search([]):
|
||||||
|
days_before = company.contract_pregenerate_days or 0
|
||||||
|
cutoffdate = (
|
||||||
|
today + relativedelta(days=days_before)
|
||||||
|
).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
contracts = self.with_context(cron=True).search([
|
contracts = self.with_context(cron=True).search([
|
||||||
|
('company_id', '=', company.id),
|
||||||
('recurring_invoices', '=', True),
|
('recurring_invoices', '=', True),
|
||||||
('recurring_next_date', '<=', today),
|
('recurring_next_date', '<=', cutoffdate),
|
||||||
'|',
|
'|',
|
||||||
('date_end', '=', False),
|
('date_end', '=', False),
|
||||||
('date_end', '>=', today),
|
('date_end', '>=', cutoffdate),
|
||||||
])
|
])
|
||||||
return contracts.recurring_create_invoice(limit)
|
return contracts.recurring_create_invoice(limit)
|
||||||
|
|
||||||
|
|||||||
14
contract/models/res_company.py
Normal file
14
contract/models/res_company.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2019 - Therp BV <https://therp.nl>.
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResCompany(models.Model):
|
||||||
|
_inherit = 'res.company'
|
||||||
|
|
||||||
|
contract_pregenerate_days = fields.Integer(
|
||||||
|
string='Days to prepare invoices',
|
||||||
|
help="Days before next invoice date to generate draft invoices.\n"
|
||||||
|
"This allows users to check the invoices before confirmation,\n"
|
||||||
|
" and to send invoices to customers, before the invoice date.")
|
||||||
14
contract/views/res_company.xml
Normal file
14
contract/views/res_company.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_company_form" model="ir.ui.view">
|
||||||
|
<field name="inherit_id" ref="base.view_company_form" />
|
||||||
|
<field name="model">res.company</field>
|
||||||
|
<field type="xml" name="arch">
|
||||||
|
<field name="currency_id" position="after">
|
||||||
|
<field name="contract_pregenerate_days" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user