diff --git a/sale_line_refund_to_invoice_qty/__manifest__.py b/sale_line_refund_to_invoice_qty/__manifest__.py index 15a5cceb2cc..66aa858d0ae 100644 --- a/sale_line_refund_to_invoice_qty/__manifest__.py +++ b/sale_line_refund_to_invoice_qty/__manifest__.py @@ -4,7 +4,7 @@ "name": "Sale Line Refund To Invoice Qty", "summary": """Allow deciding whether refunded quantity should be considered as quantity to reinvoice""", - "version": "15.0.2.0.1", + "version": "16.0.1.0.0", "category": "Sales", "website": "https://github.com/OCA/account-invoicing", "author": "ForgeFlow, Odoo Community Association (OCA)", diff --git a/sale_line_refund_to_invoice_qty/i18n/es.po b/sale_line_refund_to_invoice_qty/i18n/es.po new file mode 100644 index 00000000000..de1c4bc3204 --- /dev/null +++ b/sale_line_refund_to_invoice_qty/i18n/es.po @@ -0,0 +1,70 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_line_refund_to_invoice_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model,name:sale_line_refund_to_invoice_qty.model_account_move_reversal +msgid "Account Move Reversal" +msgstr "Reversión de asiento contable" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model,name:sale_line_refund_to_invoice_qty.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model,name:sale_line_refund_to_invoice_qty.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model.fields,help:sale_line_refund_to_invoice_qty.field_account_move_line__sale_qty_to_reinvoice +msgid "Leave it marked if you will reinvoice the same sale order line" +msgstr "Déjelo marcado si va a volver a facturar la misma línea de pedido de venta" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model.fields,help:sale_line_refund_to_invoice_qty.field_account_move_reversal__sale_qty_to_reinvoice +msgid "" +"Leave it marked if you will reinvoice the same sale order line (standard " +"behaviour)" +msgstr "Déjelo marcado si va a volver a facturar la misma línea de pedido de venta " +"(comportamiento estándar)" + +#. module: sale_line_refund_to_invoice_qty +#: model_terms:ir.ui.view,arch_db:sale_line_refund_to_invoice_qty.view_account_move_reversal +msgid "" +"Leave it marked when other customer invoices are expected for the quantities" +" in the credit note." +msgstr "Déjelo marcado cuando se esperen otras facturas de clientes por las " +"cantidades de la factura rectificativa." + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model.fields,field_description:sale_line_refund_to_invoice_qty.field_sale_order_line__qty_refunded_not_invoiceable +msgid "Quantity Refunded Not Invoiceable" +msgstr "Cantidad reembolsada no facturable" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model.fields,field_description:sale_line_refund_to_invoice_qty.field_account_move_line__sale_qty_to_reinvoice +msgid "Sale Qty To Reinvoice" +msgstr "Cantidad de venta a refacturar" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model,name:sale_line_refund_to_invoice_qty.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#. module: sale_line_refund_to_invoice_qty +#: model:ir.model.fields,field_description:sale_line_refund_to_invoice_qty.field_account_move_reversal__sale_qty_to_reinvoice +msgid "This credit note will be reinvoiced" +msgstr "Esta factura rectificativa será refacturada" diff --git a/sale_line_refund_to_invoice_qty/migrations/15.0.2.0.1/post-fix-old-field-value.py b/sale_line_refund_to_invoice_qty/migrations/15.0.2.0.1/post-fix-old-field-value.py deleted file mode 100644 index 091f7210db9..00000000000 --- a/sale_line_refund_to_invoice_qty/migrations/15.0.2.0.1/post-fix-old-field-value.py +++ /dev/null @@ -1,60 +0,0 @@ -import logging - -from odoo import SUPERUSER_ID, api - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - env = api.Environment(cr, SUPERUSER_ID, {}) - sol_model = env["sale.order.line"] - field_definition = env["ir.model.fields"].search( - [("name", "=", "sale_qty_to_reinvoice"), ("model", "=", "account.move.line")], - limit=1, - ) - if field_definition: - env.cr.execute( - """ - update account_move_line set sale_qty_to_reinvoice = True - where create_date <= %s and - (sale_qty_to_reinvoice = False or sale_qty_to_reinvoice is null) - """, - (field_definition.create_date or field_definition.write_date,), - ) - env.cr.commit() - query = """ - with invoice_lines as ( - select rel.order_line_id, sum(coalesce(aml.quantity, 0)) as quantity - from account_move_line as aml - inner join account_move as am on am.id = aml.move_id - inner join sale_order_line_invoice_rel as rel on rel.invoice_line_id = aml.id - where am.state = 'posted' and am.move_type = 'out_invoice' - group by rel.order_line_id - ), credit_lines as ( - select rel.order_line_id, sum(coalesce(aml.quantity, 0)) as quantity - from account_move_line as aml - inner join account_move as am on am.id = aml.move_id - inner join sale_order_line_invoice_rel as rel on rel.invoice_line_id = aml.id - where am.state = 'posted' and am.move_type = 'out_refund' - and aml.sale_qty_to_reinvoice = true - group by rel.order_line_id - ) - select - sol.id - from sale_order_line as sol - inner join sale_order as so on so.id = sol.order_id and so.state in ('sale', 'done') - left join invoice_lines as il on sol.id = il.order_line_id - left join credit_lines as cl on sol.id = cl.order_line_id - where (coalesce(il.quantity, 0) - coalesce(cl.quantity, 0)) != sol.qty_invoiced - - """ - env.cr.execute(query) - lines_with_problems = [data[0] for data in env.cr.fetchall()] - if lines_with_problems: - _logger.debug("total lines to reprocess: %s", str(len(lines_with_problems))) - sol_model.search( - [ - ("id", "in", lines_with_problems), - ("product_id.type", "!=", "service"), - ] - )._compute_qty_invoiced() diff --git a/sale_line_refund_to_invoice_qty/models/account.py b/sale_line_refund_to_invoice_qty/models/account.py index 2509a054145..061ad0b2a7f 100644 --- a/sale_line_refund_to_invoice_qty/models/account.py +++ b/sale_line_refund_to_invoice_qty/models/account.py @@ -1,28 +1,26 @@ # 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 +from odoo import api, fields, models class AccountMove(models.Model): _inherit = "account.move" - def _reverse_move_vals(self, default_values, cancel=True): + @api.returns("self", lambda value: value.id) + def copy(self, default=None): # Set the sale_qty_to_reinvoice based on the boolean from the # reversal wizard - move_vals = super(AccountMove, self)._reverse_move_vals( - default_values, cancel=cancel - ) + res = super().copy(default=default) sale_qty_to_reinvoice = self.env.context.get("sale_qty_to_reinvoice", False) - for vals in move_vals["line_ids"]: - vals[2].update({"sale_qty_to_reinvoice": sale_qty_to_reinvoice}) - return move_vals + res.line_ids.write({"sale_qty_to_reinvoice": sale_qty_to_reinvoice}) + return res class AccountMoveLine(models.Model): _inherit = "account.move.line" sale_qty_to_reinvoice = fields.Boolean( - string="Sale qty to reinvoice", default=True, help="Leave it marked if you will reinvoice the same sale order line", + copy=False, ) diff --git a/sale_line_refund_to_invoice_qty/models/sale.py b/sale_line_refund_to_invoice_qty/models/sale.py index f43b2d71366..7624d257423 100644 --- a/sale_line_refund_to_invoice_qty/models/sale.py +++ b/sale_line_refund_to_invoice_qty/models/sale.py @@ -33,7 +33,8 @@ def _compute_qty_invoiced(self): qty_invoiced += invoice_line.product_uom_id._compute_quantity( invoice_line.quantity, line.product_uom ) - line.qty_invoiced = qty_invoiced + if line.qty_invoiced != qty_invoiced: + line.qty_invoiced = qty_invoiced return res @api.depends( diff --git a/sale_line_refund_to_invoice_qty/wizards/account_move_reversal.py b/sale_line_refund_to_invoice_qty/wizards/account_move_reversal.py index 34ca3b73101..4fbcc03e59f 100644 --- a/sale_line_refund_to_invoice_qty/wizards/account_move_reversal.py +++ b/sale_line_refund_to_invoice_qty/wizards/account_move_reversal.py @@ -14,7 +14,10 @@ class AccountMoveReversal(models.TransientModel): ) def reverse_moves(self): + sale_qty_to_reinvoice = ( + True if self.refund_method == "modify" else self.sale_qty_to_reinvoice + ) return super( AccountMoveReversal, - self.with_context(sale_qty_to_reinvoice=self.sale_qty_to_reinvoice), + self.with_context(sale_qty_to_reinvoice=sale_qty_to_reinvoice), ).reverse_moves() diff --git a/sale_line_refund_to_invoice_qty/wizards/account_move_reversal_view.xml b/sale_line_refund_to_invoice_qty/wizards/account_move_reversal_view.xml index eca3f47d296..e4eec4b8738 100644 --- a/sale_line_refund_to_invoice_qty/wizards/account_move_reversal_view.xml +++ b/sale_line_refund_to_invoice_qty/wizards/account_move_reversal_view.xml @@ -8,7 +8,7 @@