Skip to content

Commit 95f08ab

Browse files
zamberjodocker-odoo
authored and
docker-odoo
committed
[ADD] Módulo account_invoice_mode_multi_monthday: (#5)
Creates monthly invoices for customer on a indicated (one or several) days of the month. (configuration is in Accounting Settings)
1 parent cbd87a0 commit 95f08ab

23 files changed

+1001
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
===================================
2+
Account Invoice Mode Multi Monthday
3+
===================================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github
17+
:target: https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_mode_multi_monthday
18+
:alt: OCA/account-invoicing
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_mode_multi_monthday
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/95/14.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module allows to select a multiple days month invoicing mode for a customer.
29+
It is based on `account_invoice_base_invoicing_mode`.
30+
When this mode is selected for a customer, the customer will be automatically
31+
invoiced
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Known issues / Roadmap
39+
======================
40+
41+
42+
Bug Tracker
43+
===========
44+
45+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_.
46+
In case of trouble, please check there if your issue has already been reported.
47+
If you spotted it first, help us smashing it by providing a detailed and welcomed
48+
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_mode_multi_monthday%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
49+
50+
Do not contact contributors directly about support or help with technical issues.
51+
52+
Credits
53+
=======
54+
55+
Authors
56+
~~~~~~~
57+
58+
* Aures TIC
59+
60+
Contributors
61+
~~~~~~~~~~~~
62+
63+
* `Aures TIC <https://aurestic.es/>`_:
64+
65+
* Jose Zambudio <jose@aurestic.es>
66+
* Anna Martinez <anna@aurestic.es>
67+
68+
Other credits
69+
~~~~~~~~~~~~~
70+
71+
The development of this module has been financially supported by:
72+
73+
* Aures TIC
74+
75+
Maintainers
76+
~~~~~~~~~~~
77+
78+
This module is maintained by the OCA.
79+
80+
.. image:: https://odoo-community.org/logo.png
81+
:alt: Odoo Community Association
82+
:target: https://odoo-community.org
83+
84+
OCA, or the Odoo Community Association, is a nonprofit organization whose
85+
mission is to support the collaborative development of Odoo features and
86+
promote its widespread use.
87+
88+
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_mode_multi_monthday>`_ project on GitHub.
89+
90+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2022 Aures TIC
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Account Invoice Mode Multi Monthday",
5+
"version": "14.0.1.1.0",
6+
"summary": "Create invoices automatically multi monthday.",
7+
"author": "Aures TIC, Odoo Community Association (OCA)",
8+
"website": "https://github.com/OCA/account-invoicing",
9+
"license": "AGPL-3",
10+
"category": "Accounting & Finance",
11+
"depends": [
12+
"account",
13+
"account_invoice_base_invoicing_mode",
14+
"queue_job",
15+
"sale",
16+
"stock",
17+
],
18+
"data": [
19+
"data/ir_cron.xml",
20+
"data/queue_job_data.xml",
21+
"views/res_config_settings_views.xml",
22+
],
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo noupdate="1">
3+
4+
<record forcecreate="True" id="ir_cron_generate_multi_monthday_invoice" model="ir.cron">
5+
<field name="name">Generate multi monthday invoices</field>
6+
<field eval="True" name="active" />
7+
<field name="user_id" ref="base.user_root" />
8+
<field name="interval_number">1</field>
9+
<field name="interval_type">days</field>
10+
<field name="numbercall">-1</field>
11+
<field eval="False" name="doall" />
12+
<field name="model_id" ref="model_sale_order" />
13+
<field name="code">model.cron_generate_multi_monthday_invoices()</field>
14+
<field
15+
name="nextcall"
16+
eval="(DateTime.now().replace(hour=23,minute=59).strftime('%Y-%m-%d %H:%M:%S'))"
17+
/>
18+
</record>
19+
20+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<data>
4+
5+
<!-- Queue Job Channel -->
6+
<record id="invoice_multi_monthday" model="queue.job.channel">
7+
<field name="name">invoice_multi_monthday</field>
8+
<field name="parent_id" ref="queue_job.channel_root" />
9+
</record>
10+
11+
<!-- Queue Job Function -->
12+
<record id="job_function_generate_invoices_by_partner" model="queue.job.function">
13+
<field name="model_id" ref="sale.model_sale_order" />
14+
<field name="method">_generate_invoices_by_partner</field>
15+
<field name="channel_id" ref="invoice_multi_monthday" />
16+
</record>
17+
18+
</data>
19+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import res_company
2+
from . import res_config_settings
3+
from . import res_partner
4+
from . import sale_order
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2022 Aures TIC
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import api, fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
invoicing_mode_multi_monthday_last_execution = fields.Datetime(
11+
string="Last execution",
12+
help="Last execution of multi monthday invoicing.",
13+
readonly=True,
14+
)
15+
invoicing_mode_multi_monthday_days = fields.Char(
16+
string="Month days to invoice",
17+
help="Month days to invoice (sepparated with commas)",
18+
)
19+
20+
def write(self, values):
21+
if "invoicing_mode_multi_monthday_days" in values:
22+
values[
23+
"invoicing_mode_multi_monthday_days"
24+
] = self.fix_typo_comma_sepparated(
25+
values.get("invoicing_mode_multi_monthday_days")
26+
)
27+
return super(ResCompany, self).write(values)
28+
29+
@api.model
30+
def fix_typo_comma_sepparated(self, days):
31+
return ",".join(
32+
filter(
33+
lambda val: val and val.isnumeric() and 0 < int(val) < 31,
34+
days.split(","),
35+
)
36+
)
37+
38+
def get_invoicing_month_days(self):
39+
self.ensure_one()
40+
return (
41+
self.invoicing_mode_multi_monthday_days
42+
and map(int, self.invoicing_mode_multi_monthday_days.split(","))
43+
or []
44+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2022 Aures TIC
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
from odoo import fields, models
4+
5+
6+
class ResConfigSettings(models.TransientModel):
7+
_inherit = "res.config.settings"
8+
9+
invoicing_mode_multi_monthday_last_execution = fields.Datetime(
10+
related="company_id.invoicing_mode_multi_monthday_last_execution",
11+
readonly=True,
12+
)
13+
invoicing_mode_multi_monthday_days = fields.Char(
14+
related="company_id.invoicing_mode_multi_monthday_days",
15+
readonly=False,
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022 Aures TIC
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import fields, models
5+
6+
7+
class ResPartner(models.Model):
8+
_inherit = "res.partner"
9+
10+
invoicing_mode = fields.Selection(
11+
selection_add=[("multi_monthday", "Multi monthday")],
12+
ondelete={"multi_monthday": "set default"},
13+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2022 Aures TIC
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import api, fields, models
5+
6+
7+
class SaleOrder(models.Model):
8+
_inherit = "sale.order"
9+
10+
@api.model
11+
def cron_generate_multi_monthday_invoices(self):
12+
"""Cron called daily to check if multi_monthday invoicing needs to be done."""
13+
companies = self._company_multi_monthday_invoicing_today()
14+
if companies:
15+
self.generate_multi_monthday_invoices(companies)
16+
17+
@api.model
18+
def generate_multi_monthday_invoices(self, companies=None):
19+
"""Generate invoices for customers who require that mode.
20+
21+
Invoices will be generated by other jobs split for different customer
22+
and different payment term.
23+
"""
24+
if not companies:
25+
companies = self.company_id
26+
saleorder_groups = self.read_group(
27+
[
28+
("invoicing_mode", "=", "multi_monthday"),
29+
("invoice_status", "=", "to invoice"),
30+
("company_id", "in", companies.ids),
31+
],
32+
["partner_invoice_id"],
33+
groupby=self._get_groupby_fields_for_multi_monthday_invoicing(),
34+
lazy=False,
35+
)
36+
for saleorder_group in saleorder_groups:
37+
saleorder_ids = self.search(saleorder_group["__domain"]).ids
38+
self.with_delay()._generate_invoices_by_partner(saleorder_ids)
39+
companies.write(
40+
{
41+
"invoicing_mode_multi_monthday_last_execution": fields.Datetime.now(),
42+
}
43+
)
44+
return saleorder_groups
45+
46+
@api.model
47+
def _get_groupby_fields_for_multi_monthday_invoicing(self):
48+
"""Returns the sale order fields used to group them into jobs."""
49+
return ["partner_invoice_id", "payment_term_id"]
50+
51+
def _generate_invoices_by_partner(
52+
self, saleorder_ids, invoicing_mode="multi_monthday"
53+
):
54+
"""Generate invoices for a group of sale order belonging to a customer."""
55+
sales = (
56+
self.browse(saleorder_ids)
57+
.exists()
58+
.filtered(lambda r: r.invoice_status == "to invoice")
59+
)
60+
if not sales:
61+
return "No sale order found to invoice ?"
62+
invoices = sales._create_invoices(
63+
grouped=sales[:1].partner_invoice_id.one_invoice_per_order, final=True
64+
)
65+
for invoice in invoices:
66+
invoice.with_delay()._validate_invoice()
67+
return invoices
68+
69+
@api.model
70+
def _company_multi_monthday_invoicing_today(self):
71+
"""Get company ids for which today is invoicing day."""
72+
companies = self.env["res.company"]
73+
now = fields.Datetime.now()
74+
return companies.search([]).filtered(
75+
lambda company: now.day in company.get_invoicing_month_days()
76+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* `Aures TIC <https://aurestic.es/>`_:
2+
3+
* Jose Zambudio <jose@aurestic.es>
4+
* Anna Martinez <anna@aurestic.es>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The development of this module has been financially supported by:
2+
3+
* Aures TIC
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This module allows to select a multi_monthday invoicing mode for a customer.
2+
It is based on `account_invoice_base_invoicing_mode`.
3+
When this mode is selected for a customer, the customer will be automatically
4+
invoiced every indicated days of the month

account_invoice_mode_multi_monthday/readme/INSTALL.rst

Whitespace-only changes.

account_invoice_mode_multi_monthday/readme/ROADMAP.rst

Whitespace-only changes.
Loading

0 commit comments

Comments
 (0)