-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MIG][16.0] partner_invoicing_mode_weekly (rename account_invoice_mode_weekly) #1514
Open
rousseldenis
wants to merge
16
commits into
OCA:16.0
Choose a base branch
from
acsone:16.0-mig-partner-invoicing-mode-weekly-dro
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0beb30b
[14.0][ADD] account_invoice_mode_weekly
jcoux 908ea1c
[UPD] Update account_invoice_mode_weekly.pot
oca-travis 3aab69d
[UPD] README.rst
OCA-git-bot b5dac45
[ADD] icon.png
OCA-git-bot 8aa4ed4
[IMP] account_invoice_mode_*: Add ondelete attribute to 'invoicing_mo…
SilvioC2C 0710a2c
account_invoice_mode_weekly 14.0.1.1.0
OCA-git-bot 0380912
Added translation using Weblate (Dutch)
bosd e8df2d0
Translated using Weblate (Dutch)
bosd 257755a
Added translation using Weblate (Catalan)
extrememicro 07342f0
Added translation using Weblate (Spanish)
anmarmo1 ea6cc04
Translated using Weblate (Spanish)
anmarmo1 15b78cb
[MIG][16.0] partner_invoicing_mode (rename account_invoice_mode_weekly)
rousseldenis 93e3ddb
[IMP] partner_invoicing_mode_weekly: Don't depend on stock
rousseldenis e5aa028
[IMP] partner_invoicing_mode_weekly: Add test for cron job
rousseldenis 775014b
[IMP] partner_invoicing_mode_weekly: Adapt code to refactor in base m…
rousseldenis b17ec89
[DONT MERGE] test-requirements.txt
rousseldenis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2021 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Account Invoice Mode Weekly", | ||
"version": "14.0.1.0.0", | ||
"summary": "Create invoices automatically on a weekly basis.", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"license": "AGPL-3", | ||
"category": "Accounting & Finance", | ||
"depends": [ | ||
"account", | ||
"account_invoice_base_invoicing_mode", | ||
"queue_job", | ||
"sale", | ||
"stock", # For unit tests | ||
], | ||
"data": [ | ||
"data/ir_cron.xml", | ||
"data/queue_job_data.xml", | ||
"views/res_config_settings_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo noupdate="1"> | ||
<record forcecreate="True" id="ir_cron_generate_weekly_invoice" model="ir.cron"> | ||
<field name="name">Generate Weekly Invoices</field> | ||
<field eval="True" name="active" /> | ||
<field name="user_id" ref="base.user_root" /> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field eval="False" name="doall" /> | ||
<field name="model_id" ref="model_sale_order" /> | ||
<field name="code">model.cron_generate_weekly_invoices()</field> | ||
<field | ||
name="nextcall" | ||
eval="(DateTime.now().replace(hour=1,minute=0).strftime('%Y-%m-%d %H:%M:%S'))" | ||
/> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<!-- Queue Job Channel --> | ||
<record id="invoice_weekly" model="queue.job.channel"> | ||
<field name="name">invoice_weekly</field> | ||
<field name="parent_id" ref="queue_job.channel_root" /> | ||
</record> | ||
|
||
<!-- Queue Job Function --> | ||
<record id="job_function_generate_invoices_by_partner" model="queue.job.function"> | ||
<field name="model_id" ref="sale.model_sale_order" /> | ||
<field name="method">_generate_invoices_by_partner</field> | ||
<field name="channel_id" ref="invoice_weekly" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_invoice_mode_weekly | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2021-06-28 08:02+0000\n" | ||
"PO-Revision-Date: 2021-06-28 08:02+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model_terms:ir.ui.view,arch_db:account_invoice_mode_weekly.res_config_settings_view_form | ||
msgid "<span class=\"o_form_label\">Weekly Invoicing Options</span>" | ||
msgstr "<span class=\"o_form_label\">Options pour la facturation hebdomadaire</span>" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model,name:account_invoice_mode_weekly.model_res_company | ||
msgid "Companies" | ||
msgstr "Sociétés" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model,name:account_invoice_mode_weekly.model_res_config_settings | ||
msgid "Config Settings" | ||
msgstr "Paramètres de config" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model,name:account_invoice_mode_weekly.model_res_partner | ||
msgid "Contact" | ||
msgstr "" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,help:account_invoice_mode_weekly.field_res_company__invoicing_mode_weekly_day_todo | ||
#: model:ir.model.fields,help:account_invoice_mode_weekly.field_res_config_settings__res_invoicing_mode_weekly_day_todo | ||
msgid "Day of the week to execute the invoicing." | ||
msgstr "Jour de la semaine pour exécuter la facturation." | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_company__display_name | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_config_settings__display_name | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_partner__display_name | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_sale_order__display_name | ||
msgid "Display Name" | ||
msgstr "Nom affiché" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__4 | ||
msgid "Friday" | ||
msgstr "Vendredi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.actions.server,name:account_invoice_mode_weekly.ir_cron_generate_weekly_invoice_ir_actions_server | ||
#: model:ir.cron,cron_name:account_invoice_mode_weekly.ir_cron_generate_weekly_invoice | ||
#: model:ir.cron,name:account_invoice_mode_weekly.ir_cron_generate_weekly_invoice | ||
msgid "Generate Weekly Invoices" | ||
msgstr "Générer les factures hebdomadaires" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_company__id | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_config_settings__id | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_partner__id | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_sale_order__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_partner__invoicing_mode | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_users__invoicing_mode | ||
msgid "Invoicing Mode" | ||
msgstr "Mode de facturation" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model_terms:ir.ui.view,arch_db:account_invoice_mode_weekly.res_config_settings_view_form | ||
msgid "Invoicing Weekly" | ||
msgstr "Facturation hebdomadaire" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_company____last_update | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_config_settings____last_update | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_partner____last_update | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_sale_order____last_update | ||
msgid "Last Modified on" | ||
msgstr "Dernière modification le" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model_terms:ir.ui.view,arch_db:account_invoice_mode_weekly.res_config_settings_view_form | ||
msgid "Last executed on" | ||
msgstr "Dernière exécution le" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,help:account_invoice_mode_weekly.field_res_company__invoicing_mode_weekly_last_execution | ||
#: model:ir.model.fields,help:account_invoice_mode_weekly.field_res_config_settings__invoicing_mode_weekly_last_execution | ||
msgid "Last execution of weekly invoicing." | ||
msgstr "Dernière exécution de la facturation hebdomadaire" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__0 | ||
msgid "Monday" | ||
msgstr "Lundi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model,name:account_invoice_mode_weekly.model_sale_order | ||
msgid "Sales Order" | ||
msgstr "Bon de commande" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__5 | ||
msgid "Saturday" | ||
msgstr "Samedi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__6 | ||
msgid "Sunday" | ||
msgstr "Dimanche" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__3 | ||
msgid "Thursday" | ||
msgstr "Jeudi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__1 | ||
msgid "Tuesday" | ||
msgstr "Mardi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_company__invoicing_mode_weekly_day_todo__2 | ||
msgid "Wednesday" | ||
msgstr "Mercredi" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields.selection,name:account_invoice_mode_weekly.selection__res_partner__invoicing_mode__weekly | ||
msgid "Weekly" | ||
msgstr "Hebdomadaire" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_company__invoicing_mode_weekly_day_todo | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_config_settings__res_invoicing_mode_weekly_day_todo | ||
msgid "Weekly Invoicing Day" | ||
msgstr "Jour de facturation hebdomadaire" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model_terms:ir.ui.view,arch_db:account_invoice_mode_weekly.res_config_settings_view_form | ||
msgid "Weekly invoicing day" | ||
msgstr "Jour de facturation hebdomadaire" | ||
|
||
#. module: account_invoice_mode_weekly | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_company__invoicing_mode_weekly_last_execution | ||
#: model:ir.model.fields,field_description:account_invoice_mode_weekly.field_res_config_settings__invoicing_mode_weekly_last_execution | ||
msgid "Weekly last execution" | ||
msgstr "Dernière exécution hebdomadaire" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import res_company | ||
from . import res_config_settings | ||
from . import res_partner | ||
from . import sale_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
invoicing_mode_weekly_day_todo = fields.Selection( | ||
selection=[ | ||
("0", "Monday"), | ||
("1", "Tuesday"), | ||
("2", "Wednesday"), | ||
("3", "Thursday"), | ||
("4", "Friday"), | ||
("5", "Saturday"), | ||
("6", "Sunday"), | ||
], | ||
default="0", | ||
string="Weekly Invoicing Day", | ||
help="Day of the week to execute the invoicing.", | ||
) | ||
invoicing_mode_weekly_last_execution = fields.Datetime( | ||
string="Weekly last execution", | ||
help="Last execution of weekly invoicing.", | ||
readonly=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
res_invoicing_mode_weekly_day_todo = fields.Selection( | ||
related="company_id.invoicing_mode_weekly_day_todo", readonly=False | ||
) | ||
invoicing_mode_weekly_last_execution = fields.Datetime( | ||
related="company_id.invoicing_mode_weekly_last_execution", | ||
readonly=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
invoicing_mode = fields.Selection(selection_add=([("weekly", "Weekly")])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from datetime import datetime | ||
|
||
from odoo import api, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
@api.model | ||
def cron_generate_weekly_invoices(self): | ||
"""Cron called daily to check if weekly invoicing needs to be done.""" | ||
company_ids = self._company_weekly_invoicing_today() | ||
if company_ids: | ||
self.generate_weekly_invoices(company_ids) | ||
|
||
@api.model | ||
def generate_weekly_invoices(self, companies=None): | ||
"""Generate weekly invoices for customers who require that mode. | ||
|
||
Invoices will be generated by other jobs split for different customer | ||
and different payment term. | ||
""" | ||
if not companies: | ||
companies = self.company_id | ||
saleorder_groups = self.read_group( | ||
[ | ||
("invoicing_mode", "=", "weekly"), | ||
("invoice_status", "=", "to invoice"), | ||
("company_id", "in", companies.ids), | ||
], | ||
["partner_invoice_id"], | ||
groupby=self._get_groupby_fields_for_weekly_invoicing(), | ||
lazy=False, | ||
) | ||
for saleorder_group in saleorder_groups: | ||
saleorder_ids = self.search(saleorder_group["__domain"]).ids | ||
self.with_delay()._generate_invoices_by_partner(saleorder_ids) | ||
companies.write({"invoicing_mode_weekly_last_execution": datetime.now()}) | ||
return saleorder_groups | ||
|
||
@api.model | ||
def _get_groupby_fields_for_weekly_invoicing(self): | ||
"""Returns the sale order fields used to group them into jobs.""" | ||
return ["partner_invoice_id", "payment_term_id"] | ||
|
||
def _generate_invoices_by_partner(self, saleorder_ids, invoicing_mode="weekly"): | ||
"""Generate invoices for a group of sale order belonging to a customer.""" | ||
sales = ( | ||
self.browse(saleorder_ids) | ||
.exists() | ||
.filtered(lambda r: r.invoice_status == "to invoice") | ||
) | ||
if not sales: | ||
return "No sale order found to invoice ?" | ||
invoices = sales._create_invoices( | ||
grouped=sales[0].partner_invoice_id.one_invoice_per_order, | ||
final=True, | ||
) | ||
for invoice in invoices: | ||
invoice.with_delay()._validate_invoice() | ||
return invoices | ||
|
||
@api.model | ||
def _company_weekly_invoicing_today(self): | ||
"""Get company ids for which today is weekly invoicing day.""" | ||
today = datetime.now() | ||
domain = [ | ||
"|", | ||
("invoicing_mode_weekly_last_execution", "<", today), | ||
("invoicing_mode_weekly_last_execution", "=", False), | ||
("invoicing_mode_weekly_day_todo", "=", today.weekday()), | ||
] | ||
return self.env["res.company"].search(domain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Camptocamp <https://www.camptocamp.com>`_: | ||
|
||
* Julien Coux <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The development of this module has been financially supported by: | ||
|
||
* Camptocamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This module allows to select a weekly invoicing mode for a customer. | ||
It is based on `account_invoice_base_invoicing_mode`. | ||
When this mode is selected for a customer, the customer will be automatically | ||
invoiced |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import test_invoice_mode_weekly | ||
from . import test_invoice_mode_weekly_is_it_today |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StefanRijnhart @jcoux After having read this, it's impossible to have several modes on the same instance as:
I'll try to fix that