-
-
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 StefanRijnhart
- Loading branch information
Showing
17 changed files
with
630 additions
and
0 deletions.
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 @@ | ||
from . import models |
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 @@ | ||
# 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
15
partner_invoicing_mode_at_shipping/data/queue_job_data.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,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> |
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 @@ | ||
from . import res_partner | ||
from . import stock_move | ||
from . import stock_picking |
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,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"}, | ||
) |
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,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
49
partner_invoicing_mode_at_shipping/models/stock_picking.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,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() | ||
) |
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,5 @@ | ||
* `Camptocamp <https://www.camptocamp.com>`_: | ||
|
||
* Thierry Ducrest <[email protected]> | ||
|
||
* Phuc (Tran Thanh) <[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 `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.
Oops, something went wrong.