Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
7
sale_line_refund_to_invoice_qty/models/__init__.py
Normal file
7
sale_line_refund_to_invoice_qty/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from . import account_move
|
||||
from . import account_move_line
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import sale_order_line
|
||||
15
sale_line_refund_to_invoice_qty/models/account_move.py
Normal file
15
sale_line_refund_to_invoice_qty/models/account_move.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from odoo import models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
def copy(self, default=None):
|
||||
# Set the sale_qty_to_reinvoice based on the boolean from the
|
||||
# reversal wizard
|
||||
res = super().copy(default=default)
|
||||
sale_qty_to_reinvoice = self.env.context.get("sale_qty_to_reinvoice", False)
|
||||
res.line_ids.write({"sale_qty_to_reinvoice": sale_qty_to_reinvoice})
|
||||
return res
|
||||
13
sale_line_refund_to_invoice_qty/models/account_move_line.py
Normal file
13
sale_line_refund_to_invoice_qty/models/account_move_line.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
sale_qty_to_reinvoice = fields.Boolean(
|
||||
default=lambda self: self.env.company.reinvoice_credit_note_default,
|
||||
help="Leave it marked if you will reinvoice the same sale order line",
|
||||
copy=False,
|
||||
)
|
||||
9
sale_line_refund_to_invoice_qty/models/res_company.py
Normal file
9
sale_line_refund_to_invoice_qty/models/res_company.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
reinvoice_credit_note_default = fields.Boolean(
|
||||
"Reinvoice credit notes by default", default=True
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
reinvoice_credit_note_default = fields.Boolean(
|
||||
related="company_id.reinvoice_credit_note_default",
|
||||
readonly=False,
|
||||
)
|
||||
58
sale_line_refund_to_invoice_qty/models/sale_order_line.py
Normal file
58
sale_line_refund_to_invoice_qty/models/sale_order_line.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
qty_refunded_not_invoiceable = fields.Float(
|
||||
compute="_compute_qty_refunded_not_invoiceable",
|
||||
string="Quantity Refunded Not Invoiceable",
|
||||
digits="Product Unit of Measure",
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
"invoice_lines.move_id.state",
|
||||
"invoice_lines.quantity",
|
||||
"untaxed_amount_to_invoice",
|
||||
"invoice_lines.sale_qty_to_reinvoice",
|
||||
)
|
||||
def _compute_qty_invoiced(self):
|
||||
res = super()._compute_qty_invoiced()
|
||||
# Revert effect of refunds in invoice_qty when `sale_qty_to_reinvoice`
|
||||
# is not set.
|
||||
for line in self:
|
||||
qty_invoiced = line.qty_invoiced
|
||||
for invoice_line in line.invoice_lines:
|
||||
if (
|
||||
invoice_line.move_id.state != "cancel"
|
||||
and invoice_line.move_id.move_type == "out_refund"
|
||||
and not invoice_line.sale_qty_to_reinvoice
|
||||
):
|
||||
qty_invoiced += invoice_line.product_uom_id._compute_quantity(
|
||||
invoice_line.quantity, line.product_uom
|
||||
)
|
||||
if line.qty_invoiced != qty_invoiced:
|
||||
line.qty_invoiced = qty_invoiced
|
||||
return res
|
||||
|
||||
@api.depends(
|
||||
"product_uom_qty",
|
||||
"invoice_lines.move_id.state",
|
||||
"invoice_lines.quantity",
|
||||
"invoice_lines.sale_qty_to_reinvoice",
|
||||
)
|
||||
def _compute_qty_refunded_not_invoiceable(self):
|
||||
for line in self:
|
||||
qty_ref_not_inv = 0.0
|
||||
for invoice_line in line.invoice_lines:
|
||||
if (
|
||||
invoice_line.move_id.state != "cancel"
|
||||
and invoice_line.move_id.move_type == "out_refund"
|
||||
and not invoice_line.sale_qty_to_reinvoice
|
||||
):
|
||||
qty_ref_not_inv += invoice_line.product_uom_id._compute_quantity(
|
||||
invoice_line.quantity, line.product_uom
|
||||
)
|
||||
line.qty_refunded_not_invoiceable = qty_ref_not_inv
|
||||
Reference in New Issue
Block a user