-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 pedrobaeza
- Loading branch information
Showing
17 changed files
with
119 additions
and
253 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
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 @@ Sale invoice Policy | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:3c1505e28f76dfda1fccdabb3cce63bab46df277823c4236d77da275a16a5a3c | ||
!! source digest: sha256:f7cef4d695f93f0893a61a5db0dc5ea532311d04314a81189214b7a49d43faed | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -70,6 +70,8 @@ Contributors | |
* Denis Roussel <[email protected]> | ||
* Alexei Rivera <[email protected]> | ||
* Luis J. Salvatierra <[email protected]> | ||
* Alejandro Ji Cheung <[email protected]> | ||
* Ioan Galan <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
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 .post_init_hook import post_init_hook |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from . import product_template | ||
from . import res_config_settings | ||
from . import sale_order | ||
from . import sale_order_line |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,68 +1,102 @@ | ||
# Copyright 2017 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
|
||
_inherit = "sale.order.line" | ||
|
||
@api.depends( | ||
"qty_invoiced", | ||
"qty_delivered", | ||
"product_uom_qty", | ||
"order_id.state", | ||
"state", | ||
"order_id.invoice_policy", | ||
) | ||
def _compute_qty_to_invoice(self): | ||
invoice_policies = set(self.mapped("order_id.invoice_policy")) | ||
line_by_id = {line.id: line for line in self} | ||
done_lines = self.env["sale.order.line"].browse() | ||
for invoice_policy in invoice_policies: | ||
so_lines = ( | ||
self.with_context(invoice_policy=invoice_policy) | ||
.filtered(lambda x, p=invoice_policy: x.order_id.invoice_policy == p) | ||
.with_prefetch() | ||
) | ||
if so_lines: | ||
done_lines |= so_lines | ||
super(SaleOrderLine, so_lines)._compute_qty_to_invoice() | ||
for line in so_lines: | ||
# due to the change of context in compute methods, | ||
# assign the value in the modified context to self | ||
line_by_id[line.id].qty_to_invoice = line.qty_to_invoice | ||
# Not to break function if (it could not happen) some records | ||
# were not in so_lines | ||
super(SaleOrderLine, self - done_lines)._compute_qty_to_invoice() | ||
other_lines = self.filtered( | ||
lambda l: l.product_id.type == "service" | ||
or not l.order_id.invoice_policy | ||
or not l.order_id.invoice_policy_required | ||
) | ||
super(SaleOrderLine, other_lines)._compute_qty_to_invoice() | ||
for line in self - other_lines: | ||
invoice_policy = line.order_id.invoice_policy | ||
if invoice_policy == "order": | ||
line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced | ||
else: | ||
line.qty_to_invoice = line.qty_delivered - line.qty_invoiced | ||
return True | ||
|
||
@api.depends( | ||
"state", | ||
"product_uom_qty", | ||
"price_reduce", | ||
"product_id", | ||
"untaxed_amount_invoiced", | ||
"qty_delivered", | ||
"qty_to_invoice", | ||
"qty_invoiced", | ||
"product_uom_qty", | ||
"order_id.invoice_policy", | ||
) | ||
def _compute_invoice_status(self): | ||
invoice_policies = set(self.mapped("order_id.invoice_policy")) | ||
line_by_id = {line.id: line for line in self} | ||
done_lines = self.env["sale.order.line"].browse() | ||
for invoice_policy in invoice_policies: | ||
so_lines = ( | ||
self.with_context(invoice_policy=invoice_policy) | ||
.filtered(lambda x, p=invoice_policy: x.order_id.invoice_policy == p) | ||
.with_prefetch() | ||
def _compute_untaxed_amount_to_invoice(self): | ||
other_lines = self.filtered( | ||
lambda line: line.product_id.type == "service" | ||
or not line.order_id.invoice_policy | ||
or line.order_id.invoice_policy == line.product_id.invoice_policy | ||
or line.state not in ["sale", "done"] | ||
or not line.order_id.invoice_policy_required | ||
) | ||
super(SaleOrderLine, other_lines)._compute_untaxed_amount_to_invoice() | ||
for line in self - other_lines: | ||
invoice_policy = line.order_id.invoice_policy | ||
amount_to_invoice = 0.0 | ||
price_subtotal = 0.0 | ||
uom_qty_to_consider = ( | ||
line.qty_delivered | ||
if invoice_policy == "delivery" | ||
else line.product_uom_qty | ||
) | ||
done_lines |= so_lines | ||
if so_lines: | ||
super(SaleOrderLine, so_lines)._compute_invoice_status() | ||
for line in so_lines: | ||
# due to the change of context in compute methods, | ||
# assign the value in the modified context to self | ||
line_by_id[line.id].invoice_status = line.invoice_status | ||
# Not to break function if (it could not happen) some records | ||
# were not in so_lines | ||
super(SaleOrderLine, self - done_lines)._compute_invoice_status() | ||
price_reduce = line.price_unit * (1 - (line.discount or 0.0) / 100.0) | ||
price_subtotal = price_reduce * uom_qty_to_consider | ||
if len(line.tax_id.filtered(lambda tax: tax.price_include)) > 0: | ||
price_subtotal = line.tax_id.compute_all( | ||
price_reduce, | ||
currency=line.currency_id, | ||
quantity=uom_qty_to_consider, | ||
product=line.product_id, | ||
partner=line.order_id.partner_shipping_id, | ||
)["total_excluded"] | ||
inv_lines = line._get_invoice_lines() | ||
if any(inv_lines.mapped(lambda l: l.discount != line.discount)): | ||
amount = 0 | ||
for inv_line in inv_lines: | ||
if ( | ||
len(inv_line.tax_ids.filtered(lambda tax: tax.price_include)) | ||
> 0 | ||
): | ||
amount += inv_line.tax_ids.compute_all( | ||
inv_line.currency_id._convert( | ||
inv_line.price_unit, | ||
line.currency_id, | ||
line.company_id, | ||
inv_line.date or fields.Date.today(), | ||
round=False, | ||
) | ||
* inv_line.quantity | ||
)["total_excluded"] | ||
else: | ||
amount += ( | ||
inv_line.currency_id._convert( | ||
inv_line.price_unit, | ||
line.currency_id, | ||
line.company_id, | ||
inv_line.date or fields.Date.today(), | ||
round=False, | ||
) | ||
* inv_line.quantity | ||
) | ||
amount_to_invoice = max(price_subtotal - amount, 0) | ||
else: | ||
amount_to_invoice = price_subtotal - line.untaxed_amount_invoiced | ||
line.untaxed_amount_to_invoice = amount_to_invoice | ||
return True |
This file was deleted.
Oops, something went wrong.
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,5 @@ | |
* Denis Roussel <[email protected]> | ||
* Alexei Rivera <[email protected]> | ||
* Luis J. Salvatierra <[email protected]> | ||
* Alejandro Ji Cheung <[email protected]> | ||
* Ioan Galan <[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
Oops, something went wrong.