-
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by etobella
- Loading branch information
Showing
31 changed files
with
268 additions
and
290 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ Account Invoice Base Invoicing Mode | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:0d5357a79a1c0f3ca60756b83ac63eeb51024e054ac6a529f9af0e49d46d877b | ||
!! source digest: sha256:c38966d4ac8e51490419976d62f69b9bfe2967d96cd9908938478efe78f588c6 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -80,6 +80,7 @@ Contributors | |
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[email protected]> | ||
* Michael Tietz (MT Software) <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
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 |
---|---|---|
@@ -1,10 +1,64 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
from datetime import datetime | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
invoicing_mode = fields.Selection(related="partner_invoice_id.invoicing_mode") | ||
|
||
@api.model | ||
def _generate_invoices_by_partner(self, saleorder_ids): | ||
"""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 ?" | ||
sales.partner_id.ensure_one() | ||
invoices = sales._create_invoices( | ||
grouped=sales.partner_invoice_id.one_invoice_per_order, | ||
final=True, | ||
) | ||
for invoice in invoices: | ||
invoice.with_delay()._validate_invoice() | ||
return invoices | ||
|
||
@api.model | ||
def generate_invoices_by_invoice_mode( | ||
self, | ||
companies=None, | ||
invoice_mode=None, | ||
groupby=None, | ||
last_execution_field_name=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 invoice_mode: | ||
return self.env[self._name] | ||
if not companies: | ||
companies = self.company_id | ||
saleorder_groups = self.read_group( | ||
[ | ||
("invoicing_mode", "=", invoice_mode), | ||
("invoice_status", "=", "to invoice"), | ||
("company_id", "in", companies.ids), | ||
], | ||
["partner_invoice_id"], | ||
groupby=groupby, | ||
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({last_execution_field_name: datetime.now()}) | ||
return saleorder_groups |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[email protected]> | ||
* Michael Tietz (MT Software) <[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
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 @@ | ||
from . import test_invoice_base_mode |
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,70 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestInvoiceModeCommon(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
cls.SaleOrder = cls.env["sale.order"] | ||
cls.partner = cls.env.ref("base.res_partner_1") | ||
cls.partner2 = cls.env.ref("base.res_partner_2") | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "Test", "type": "service"} | ||
) | ||
cls.pt1 = cls.env["account.payment.term"].create({"name": "Term Two"}) | ||
cls.pt2 = cls.env["account.payment.term"].create({"name": "Term One"}) | ||
cls.so1 = cls.env["sale.order"].create( | ||
{ | ||
"partner_id": cls.partner.id, | ||
"partner_invoice_id": cls.partner.id, | ||
"partner_shipping_id": cls.partner.id, | ||
"payment_term_id": cls.pt1.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Line one", | ||
"product_id": cls.product.id, | ||
"product_uom_qty": 4, | ||
"product_uom": cls.product.uom_id.id, | ||
"price_unit": 123, | ||
}, | ||
) | ||
], | ||
"pricelist_id": cls.env.ref("product.list0").id, | ||
} | ||
) | ||
# Lets give the saleorder the same partner and payment terms | ||
cls.so2 = cls.env["sale.order"].create( | ||
{ | ||
"partner_id": cls.partner.id, | ||
"partner_invoice_id": cls.partner.id, | ||
"partner_shipping_id": cls.partner.id, | ||
"payment_term_id": cls.pt1.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Line one", | ||
"product_id": cls.product.id, | ||
"product_uom_qty": 4, | ||
"product_uom": cls.product.uom_id.id, | ||
"price_unit": 123, | ||
}, | ||
) | ||
], | ||
"pricelist_id": cls.env.ref("product.list0").id, | ||
} | ||
) | ||
cls.company = cls.so1.company_id | ||
|
||
def deliver_invoice(self, sale_order): | ||
sale_order.action_confirm() | ||
for line in sale_order.order_line: | ||
line.qty_delivered_manual = line.product_uom_qty |
59 changes: 59 additions & 0 deletions
59
account_invoice_base_invoicing_mode/tests/test_invoice_base_mode.py
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,59 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
from odoo import tools | ||
from odoo.tests import tagged | ||
|
||
from .common import TestInvoiceModeCommon | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestInvoiceModeBase(TestInvoiceModeCommon): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.partner.invoicing_mode = "standard" | ||
cls.partner2.invoicing_mode = "standard" | ||
|
||
def test_saleorder_with_different_mode_term(self): | ||
"""Check multiple sale order one partner diverse terms.""" | ||
self.so1.payment_term_id = self.pt1.id | ||
self.deliver_invoice(self.so1) | ||
self.so2.payment_term_id = self.pt2.id | ||
self.deliver_invoice(self.so2) | ||
with tools.mute_logger("odoo.addons.queue_job.models.base"): | ||
self.SaleOrder.with_context( | ||
test_queue_job_no_delay=True | ||
).generate_invoices_by_invoice_mode( | ||
self.company, | ||
"standard", | ||
["partner_invoice_id", "payment_term_id"], | ||
"write_date", | ||
) | ||
self.assertEqual(len(self.so1.invoice_ids), 1) | ||
self.assertEqual(len(self.so2.invoice_ids), 1) | ||
# Two invoices because the term are different | ||
self.assertNotEqual(self.so1.invoice_ids, self.so2.invoice_ids) | ||
self.assertEqual(self.so1.invoice_ids.state, "posted") | ||
|
||
def test_no_invoiceable_sale_orders(self): | ||
result = self.SaleOrder._generate_invoices_by_partner(self.so1.ids) | ||
self.assertEqual(result, "No sale order found to invoice ?") | ||
|
||
def test_no_invoice_mode(self): | ||
result = self.SaleOrder.generate_invoices_by_invoice_mode() | ||
self.assertFalse(result) | ||
|
||
def test_create_invoices_only_for_orders_company(self): | ||
self.so1.payment_term_id = self.pt1.id | ||
self.deliver_invoice(self.so1) | ||
with tools.mute_logger("odoo.addons.queue_job.models.base"): | ||
self.so1.with_context( | ||
test_queue_job_no_delay=True | ||
).generate_invoices_by_invoice_mode( | ||
companies=None, | ||
invoice_mode="standard", | ||
groupby=["partner_invoice_id", "payment_term_id"], | ||
last_execution_field_name="write_date", | ||
) | ||
self.assertEqual(len(self.so1.invoice_ids), 1) |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ Account Invoice Mode At Shipping | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:4f7ec7d48dfa1ae51d5732aeb4480e383e5963580e41a5c0a1adfaa75b72aae1 | ||
!! source digest: sha256:88adc8796b20c23c55247036f92a52ed01af848fdb28202ce7d6022ccefb6726 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -64,6 +64,7 @@ Contributors | |
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[email protected]> | ||
* Michael Tietz (MT Software) <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
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
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
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[email protected]> | ||
* Michael Tietz (MT Software) <[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
2 changes: 2 additions & 0 deletions
2
account_invoice_mode_at_shipping/tests/test_invoice_mode_at_shipping.py
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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ Account Invoice Mode Monthly | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:ff62eece66e92b37a09b8d9535cd5068918c01b86eb4234e1f2f20bd7aa689aa | ||
!! source digest: sha256:4c890aa8321275a0fba03466fed8a579689a27626ac8f7e8e314e8bf5c65a9e8 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -73,6 +73,7 @@ Contributors | |
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[email protected]> | ||
* Michael Tietz (MT Software) <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
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
Oops, something went wrong.