diff --git a/dlv_account_move_copy_ref/CHANGELOG.md b/dlv_account_move_copy_ref/CHANGELOG.md new file mode 100644 index 0000000..a6f1baf --- /dev/null +++ b/dlv_account_move_copy_ref/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [16.0.1.0.0] - 2026-10-04 + +### Added +- Initial release. +- `account.move.ref` is copied on duplicate for customer invoices and customer + credit notes (`out_invoice`, `out_refund`). +- Warning dialog (OK to continue) after the Duplicate action when the copied reference has + a value. diff --git a/dlv_account_move_copy_ref/README.md b/dlv_account_move_copy_ref/README.md new file mode 100644 index 0000000..91b39ff --- /dev/null +++ b/dlv_account_move_copy_ref/README.md @@ -0,0 +1,38 @@ +# dlv_account_move_copy_ref + +## Overview + +In core Odoo the reference of an invoice (`account.move.ref`, label +**Customer Reference** on customer documents) is not copied when the invoice is +duplicated. This addon makes it copy, and warns the user afterwards. + +## How it works + +- **Python** (`models/account_move.py`): `ref` gets `copy=True`. `copy_data()` + removes it again for every move that is not `out_invoice` / `out_refund`, so + vendor bills and journal entries keep the core behaviour. An explicit `ref` + in the `default` dict always wins (credit note reversal sets its own). +- **JS** (`static/src/js/duplicate_warning.js`): patches + `FormController.duplicateRecord`. After the duplicate, if the new record is an + `account.move` customer invoice/credit note with a non-empty `ref`, a modal alert dialog (OK button) + warning is shown: "'Customer Reference' was also copied, check + whether it is still relevant or should be removed." (nl: "'Referentie klant' + werd ook gekopieerd, kijk na of dit relevant is of dient verwijderd te + worden.") + +## Scope + +- Only the Duplicate action in the form view shows the warning. Server-side + `copy()` calls (e.g. recurring entries) copy the reference silently. +- No warning when `ref` is empty. + +## Compatibility + +- Odoo 16.0 (Community and Enterprise) +- Depends on: `account` + +## Credits + +bv Domus La Vila — https://domuslavila.eu + +License: LGPL-3 diff --git a/dlv_account_move_copy_ref/__init__.py b/dlv_account_move_copy_ref/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/dlv_account_move_copy_ref/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/dlv_account_move_copy_ref/__manifest__.py b/dlv_account_move_copy_ref/__manifest__.py new file mode 100644 index 0000000..e2efb77 --- /dev/null +++ b/dlv_account_move_copy_ref/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +{ + "name": "DLV Account Move Copy Ref", + "summary": "Copy the customer reference when duplicating a customer " + "invoice or credit note, and warn about it", + "description": """ +By default the reference (account.move.ref, shown as "Customer Reference") +is not copied when an invoice is duplicated. + +This addon copies it for customer invoices and customer credit notes +(out_invoice, out_refund). Vendor bills and journal entries are unchanged. + +After the Duplicate action in the form view, a warning dialog is shown +when the copied reference has a value, so the user can check whether it is +still relevant or has to be removed. +""", + "author": "bv Domus La Vila", + "website": "https://domuslavila.eu", + "category": "Accounting/Accounting", + "version": "16.0.1.0.0", + "license": "LGPL-3", + "depends": ["account"], + "data": [], + "assets": { + "web.assets_backend": [ + "dlv_account_move_copy_ref/static/src/js/duplicate_warning.js", + ], + }, + "installable": True, + "application": False, + "auto_install": False, +} diff --git a/dlv_account_move_copy_ref/i18n/nl.po b/dlv_account_move_copy_ref/i18n/nl.po new file mode 100644 index 0000000..204c9c9 --- /dev/null +++ b/dlv_account_move_copy_ref/i18n/nl.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * dlv_account_move_copy_ref +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: dlv_account_move_copy_ref +#. odoo-javascript +#: code:addons/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js:0 +#, python-format +msgid "" +"'Customer Reference' was also copied, check whether it is still relevant or " +"should be removed. You can find it under the 'Other Info' tab." +msgstr "" +"'Referentie klant' werd ook gekopieerd, kijk na of dit relevant is of dient " +"verwijderd te worden. Je vindt dit onder tab 'Overige info'." + +#. module: dlv_account_move_copy_ref +#. odoo-javascript +#: code:addons/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js:0 +#, python-format +msgid "Warning" +msgstr "Waarschuwing" diff --git a/dlv_account_move_copy_ref/i18n/nl_BE.po b/dlv_account_move_copy_ref/i18n/nl_BE.po new file mode 100644 index 0000000..db0506c --- /dev/null +++ b/dlv_account_move_copy_ref/i18n/nl_BE.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * dlv_account_move_copy_ref +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Language: nl_BE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: dlv_account_move_copy_ref +#. odoo-javascript +#: code:addons/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js:0 +#, python-format +msgid "" +"'Customer Reference' was also copied, check whether it is still relevant or " +"should be removed. You can find it under the 'Other Info' tab." +msgstr "" +"'Referentie klant' werd ook gekopieerd, kijk na of dit relevant is of dient " +"verwijderd te worden. Je vindt dit onder tab 'Overige info'." + +#. module: dlv_account_move_copy_ref +#. odoo-javascript +#: code:addons/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js:0 +#, python-format +msgid "Warning" +msgstr "Waarschuwing" diff --git a/dlv_account_move_copy_ref/models/__init__.py b/dlv_account_move_copy_ref/models/__init__.py new file mode 100644 index 0000000..9c0a421 --- /dev/null +++ b/dlv_account_move_copy_ref/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/dlv_account_move_copy_ref/models/account_move.py b/dlv_account_move_copy_ref/models/account_move.py new file mode 100644 index 0000000..a9cd301 --- /dev/null +++ b/dlv_account_move_copy_ref/models/account_move.py @@ -0,0 +1,20 @@ +from odoo import fields, models + +CUSTOMER_MOVE_TYPES = ("out_invoice", "out_refund") + + +class AccountMove(models.Model): + _inherit = "account.move" + + # Core has copy=False. Flipped to True here; copy_data() below limits the + # effect to customer invoices and credit notes. + ref = fields.Char(copy=True) + + def copy_data(self, default=None): + data_list = super().copy_data(default) + if default and "ref" in default: + return data_list + for move, data in zip(self, data_list): + if move.move_type not in CUSTOMER_MOVE_TYPES: + data.pop("ref", None) + return data_list diff --git a/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js b/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js new file mode 100644 index 0000000..34a8feb --- /dev/null +++ b/dlv_account_move_copy_ref/static/src/js/duplicate_warning.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ + +import { patch } from "@web/core/utils/patch"; +import { FormController } from "@web/views/form/form_controller"; +import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; + +const CUSTOMER_MOVE_TYPES = ["out_invoice", "out_refund"]; + +patch(FormController.prototype, "dlv_account_move_copy_ref", { + async duplicateRecord() { + await this._super(...arguments); + const root = this.model.root; + if ( + root.resModel === "account.move" && + CUSTOMER_MOVE_TYPES.includes(root.data.move_type) && + root.data.ref + ) { + await new Promise((resolve) => { + this.env.services.dialog.add( + AlertDialog, + { + title: this.env._t("Warning"), + body: this.env._t( + "'Customer Reference' was also copied, check whether it is " + + "still relevant or should be removed. You can find it " + + "under the 'Other Info' tab." + ), + }, + { onClose: resolve } + ); + }); + } + }, +});