Skip to content

Commit

Permalink
Merge PR #1247 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by StefanRijnhart
  • Loading branch information
OCA-git-bot committed Apr 20, 2023
2 parents 3b61454 + 6186fe8 commit 13a4be4
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions partner_invoicing_mode_at_shipping/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions partner_invoicing_mode_at_shipping/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Partner Invoicing Mode At Shipping",
"version": "15.0.1.0.0",
"summary": "Create invoices automatically when goods are shipped.",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"category": "Accounting & Finance",
"data": [
"data/queue_job_data.xml",
],
"depends": ["account", "partner_invoicing_mode", "queue_job", "stock"],
}
15 changes: 15 additions & 0 deletions partner_invoicing_mode_at_shipping/data/queue_job_data.xml
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_at_shipping" model="queue.job.channel">
<field name="name">invoice_at_shipping</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<!-- Job Functions -->
<record id="job_function_invoicing_at_shipping" model="queue.job.function">
<field name="model_id" ref="stock.model_stock_picking" />
<field name="method">_invoicing_at_shipping</field>
<field name="channel_id" ref="invoice_at_shipping" />
</record>
</odoo>
3 changes: 3 additions & 0 deletions partner_invoicing_mode_at_shipping/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_partner
from . import stock_move
from . import stock_picking
13 changes: 13 additions & 0 deletions partner_invoicing_mode_at_shipping/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 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=[("at_shipping", "At Shipping")],
ondelete={"at_shipping": "set default"},
)
19 changes: 19 additions & 0 deletions partner_invoicing_mode_at_shipping/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def _get_related_invoices(self):
"""Overridden from stock_account to return the customer invoices
related to this stock move.
"""
invoices = super()._get_related_invoices()
line_invoices = self.mapped("sale_line_id.order_id.invoice_ids").filtered(
lambda x: x.state == "posted"
)
invoices |= line_invoices
return invoices
49 changes: 49 additions & 0 deletions partner_invoicing_mode_at_shipping/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import _, models


class StockPicking(models.Model):
_inherit = "stock.picking"

def _action_done(self):
res = super()._action_done()
for picking in self:
if picking._invoice_at_shipping():
picking.with_delay()._invoicing_at_shipping()
return res

def _invoice_at_shipping(self):
"""Check if picking must be invoiced at shipping."""
self.ensure_one()
return (
self.picking_type_code == "outgoing"
and self.sale_id.partner_invoice_id.invoicing_mode == "at_shipping"
)

def _invoicing_at_shipping(self):
self.ensure_one()
sales = self.env["sale.order"].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.")

def _get_sales_order_to_invoice(self):
return self.mapped("move_lines.sale_line_id.order_id").filtered(
lambda r: r._get_invoiceable_lines()
)
5 changes: 5 additions & 0 deletions partner_invoicing_mode_at_shipping/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* `Camptocamp <https://www.camptocamp.com>`_:

* Thierry Ducrest <[email protected]>

* Phuc (Tran Thanh) <[email protected]>
3 changes: 3 additions & 0 deletions partner_invoicing_mode_at_shipping/readme/CREDITS.rst
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
4 changes: 4 additions & 0 deletions partner_invoicing_mode_at_shipping/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module allows to select a `At shipping` invoicing mode for a customer.
It is based on `partner_invoicing_mode`.
When this mode is selected the customer will be invoiced automatically on
delivery of the goods.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 13a4be4

Please sign in to comment.