Skip to content

Commit

Permalink
Merge PR #1598 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Nov 23, 2023
2 parents 03e315b + 42368e3 commit 08fe1c7
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 290 deletions.
3 changes: 2 additions & 1 deletion account_invoice_base_invoicing_mode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +80,7 @@ Contributors
* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

Other credits
~~~~~~~~~~~~~
Expand Down
56 changes: 55 additions & 1 deletion account_invoice_base_invoicing_mode/models/sale_order.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
* Michael Tietz (MT Software) <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Account Invoice Base Invoicing Mode</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0d5357a79a1c0f3ca60756b83ac63eeb51024e054ac6a529f9af0e49d46d877b
!! source digest: sha256:c38966d4ac8e51490419976d62f69b9bfe2967d96cd9908938478efe78f588c6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_base_invoicing_mode"><img alt="OCA/account-invoicing" src="https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_base_invoicing_mode"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This is a base module for implementing different invoicing mode for customers.
Expand Down Expand Up @@ -435,6 +435,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</li>
<li><p class="first">Phuc (Tran Thanh) &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</p>
</li>
<li><p class="first">Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</p>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
1 change: 1 addition & 0 deletions account_invoice_base_invoicing_mode/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_invoice_base_mode
70 changes: 70 additions & 0 deletions account_invoice_base_invoicing_mode/tests/common.py
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
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)
3 changes: 2 additions & 1 deletion account_invoice_mode_at_shipping/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +64,7 @@ Contributors
* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

Other credits
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_mode_at_shipping/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"data": [
"data/queue_job_data.xml",
],
"depends": ["account", "account_invoice_base_invoicing_mode", "queue_job", "stock"],
"depends": ["account_invoice_base_invoicing_mode", "stock"],
}
30 changes: 13 additions & 17 deletions account_invoice_mode_at_shipping/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import _, models
from odoo.tools import groupby


class StockPicking(models.Model):
Expand All @@ -24,24 +25,19 @@ def _invoice_at_shipping(self):

def _invoicing_at_shipping(self):
self.ensure_one()
sales = self.env["sale.order"].browse()
SALE = self.env["sale.order"]
sales = SALE.browse()
# Filter out non invoicable sales order
for sale in self._get_sales_order_to_invoice():
if sale._get_invoiceable_lines():
sales |= sale
# Split invoice creation on partner sales grouping on invoice settings
sales_one_invoice_per_order = sales.filtered(
"partner_invoice_id.one_invoice_per_order"
)
invoices = self.env["account.move"].browse()
if sales_one_invoice_per_order:
invoices |= sales_one_invoice_per_order._create_invoices(grouped=True)
sales_many_invoice_per_order = sales - sales_one_invoice_per_order
if sales_many_invoice_per_order:
invoices |= sales_many_invoice_per_order._create_invoices(grouped=False)
for invoice in invoices:
invoice.with_delay()._validate_invoice()
return invoices or _("Nothing to invoice.")
sales = self._get_sales_order_to_invoice()
invoice_ids = set()
for _partner_invoice, sale_orders in groupby(
sales, lambda sale_order: sale_order.partner_invoice_id
):
sale_order_ids = SALE.union(*sale_orders).ids
invoice_ids = invoice_ids.union(
set(SALE._generate_invoices_by_partner(sale_order_ids).ids)
)
return self.env["account.move"].browse(invoice_ids) or _("Nothing to invoice.")

def _get_sales_order_to_invoice(self):
return self.mapped("move_lines.sale_line_id.order_id").filtered(
Expand Down
1 change: 1 addition & 0 deletions account_invoice_mode_at_shipping/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
* Michael Tietz (MT Software) <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Account Invoice Mode At Shipping</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4f7ec7d48dfa1ae51d5732aeb4480e383e5963580e41a5c0a1adfaa75b72aae1
!! source digest: sha256:88adc8796b20c23c55247036f92a52ed01af848fdb28202ce7d6022ccefb6726
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_mode_at_shipping"><img alt="OCA/account-invoicing" src="https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_mode_at_shipping"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to select a <cite>At shipping</cite> invoicing mode for a customer.
Expand Down Expand Up @@ -415,6 +415,8 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</li>
<li><p class="first">Phuc (Tran Thanh) &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</p>
</li>
<li><p class="first">Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</p>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.tests import tagged
from odoo.tests.common import SavepointCase


@tagged("post_install", "-at_install")
class TestInvoiceModeAtShipping(SavepointCase):
@classmethod
def setUpClass(cls):
Expand Down
3 changes: 2 additions & 1 deletion account_invoice_mode_monthly/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +73,7 @@ Contributors
* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

Other credits
~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion account_invoice_mode_monthly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models
from . import tests
4 changes: 3 additions & 1 deletion account_invoice_mode_monthly/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"category": "Accounting & Finance",
"depends": ["account", "account_invoice_base_invoicing_mode", "queue_job", "sale"],
"depends": [
"account_invoice_base_invoicing_mode",
],
"data": [
"data/ir_cron.xml",
"data/queue_job_data.xml",
Expand Down
Loading

0 comments on commit 08fe1c7

Please sign in to comment.