diff --git a/account_invoice_line_default_account/README.rst b/account_invoice_line_default_account/README.rst new file mode 100644 index 00000000000..803841a80ca --- /dev/null +++ b/account_invoice_line_default_account/README.rst @@ -0,0 +1,95 @@ +==================================== +Account Invoice Line Default Account +==================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/12.0/account_invoice_line_default_account + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-12-0/account-invoicing-12-0-account_invoice_line_default_account + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/95/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When entering sales or purchase invoices directly, the user has to select an +account which will be used as a counterpart in the generated move lines. Each +supplier will mostly be linked to one account. For instance when ordering paper +from a supplier that deals in paper, the counterpart account will mostly be +something like 'office expenses'. The same principle has been applied for +customers. This module will add a default counterpart expense and income +account to a partner, comparable to the similiar field in product. When an +invoice is entered, withouth a product, the field from partner will be used as +default. Also when an account is entered on an invoice line (not automatically +selected for a product), the account will be automatically linked to the +partner as default expense or income account, unless explicitly disabled in the +partner record. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +- Remove the `write` from `account.invoice.line._onchange_account_id` +- Retrieve the real `default` attribute for field `account.invoice.line.account_id` + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV +* BCIM + +Contributors +~~~~~~~~~~~~ + +* Ronald Portier, Therp +* Jacques-Etienne Baudoux (BCIM sprl) +* `TAKOBI `_: + + * Simone Rubino + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_invoice_line_default_account/__init__.py b/account_invoice_line_default_account/__init__.py new file mode 100644 index 00000000000..b18eea37960 --- /dev/null +++ b/account_invoice_line_default_account/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_invoice_line_default_account/__manifest__.py b/account_invoice_line_default_account/__manifest__.py new file mode 100644 index 00000000000..b0c88ada966 --- /dev/null +++ b/account_invoice_line_default_account/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Therp BV () +# Copyright 2013-2018 BCIM SPRL () +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Account Invoice Line Default Account', + 'version': '12.0.1.0.0', + 'depends': [ + 'account' + ], + 'author': 'Therp BV,BCIM,Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'category': 'Accounting', + 'data': [ + 'views/res_partner.xml', + ], + 'installable': True, +} diff --git a/account_invoice_line_default_account/i18n/account_invoice_line_default_account.pot b/account_invoice_line_default_account/i18n/account_invoice_line_default_account.pot new file mode 100644 index 00000000000..d8184f44a1f --- /dev/null +++ b/account_invoice_line_default_account/i18n/account_invoice_line_default_account.pot @@ -0,0 +1,80 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-04-26 09:03+0000\n" +"PO-Revision-Date: 2022-04-26 09:03+0000\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: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__auto_update_account_expense +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__auto_update_account_expense +msgid "Autosave Selection for Expense Account on Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__auto_update_account_income +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__auto_update_account_income +msgid "Autosave Selection for Income Account on Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__property_account_expense +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__property_account_expense +msgid "Default Expense Account" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__property_account_income +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__property_account_income +msgid "Default Income Account" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__property_account_expense +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__property_account_expense +msgid "Default counterpart account for purchases on invoice lines" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__property_account_income +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__property_account_income +msgid "Default counterpart account for sales on invoice lines" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_account_invoice_line +msgid "Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__auto_update_account_expense +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__auto_update_account_expense +msgid "When an account is selected on an invoice line, automatically assign it as default expense account" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__auto_update_account_income +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__auto_update_account_income +msgid "When an account is selected on an invoice line, automatically assign it as default income account" +msgstr "" + +#. module: account_invoice_line_default_account +#: model_terms:ir.ui.view,arch_db:account_invoice_line_default_account.view_partner_expense_property_form +msgid "autosave from invoice line" +msgstr "" + diff --git a/account_invoice_line_default_account/i18n/fr.po b/account_invoice_line_default_account/i18n/fr.po new file mode 100644 index 00000000000..ecc840e3402 --- /dev/null +++ b/account_invoice_line_default_account/i18n/fr.po @@ -0,0 +1,59 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.saas~1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-18 16:01+0000\n" +"PO-Revision-Date: 2013-09-18 16:01+0000\n" +"Last-Translator: Jacques-Etienne Baudoux \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: account_invoice_line_default_account +#: field:res.partner,property_account_expense:0 +msgid "Default Expense Account" +msgstr "Compte de charge par défaut" + +#. module: account_invoice_line_default_account +#: help:res.partner,property_account_expense:0 +msgid "Default counterpart account for purchases on invoice lines" +msgstr "Compte de contrepartie par défaut pour les lignes de factures d'achat" + +#. module: account_invoice_line_default_account +#: help:res.partner,auto_update_account_expense:0 +msgid "When an account is selected on an invoice line, automatically assign it as default expense account" +msgstr "Lorsqu'un compte est sélectionné sur une ligne de facture, l'assigner automatiquement comme compte de charge par défaut" + +#. module: account_invoice_line_default_account +#: code:addons/account_invoice_line_default_account/model/account_invoice_line.py:27 +#: code:addons/account_invoice_line_default_account/model/account_invoice_line.py:47 +#, python-format +msgid "No object created for partner %d" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_account_invoice_line +msgid "Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: view:res.partner:0 +msgid "autosave from invoice line" +msgstr "sauvegarde automatique" + +#. module: account_invoice_line_default_account +#: field:res.partner,auto_update_account_expense:0 +msgid "Autosave Selection on Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_res_partner +msgid "Partner" +msgstr "" + diff --git a/account_invoice_line_default_account/i18n/it.po b/account_invoice_line_default_account/i18n/it.po new file mode 100644 index 00000000000..b9872626a60 --- /dev/null +++ b/account_invoice_line_default_account/i18n/it.po @@ -0,0 +1,80 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-04-26 08:55+0000\n" +"PO-Revision-Date: 2022-04-26 08:55+0000\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: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__auto_update_account_expense +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__auto_update_account_expense +msgid "Autosave Selection for Expense Account on Invoice Line" +msgstr "Salvare automaticamente la selezione per il conto di costo nelle righe fattura" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__auto_update_account_income +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__auto_update_account_income +msgid "Autosave Selection for Income Account on Invoice Line" +msgstr "Salvare automaticamente la selezione per il conto di ricavo nelle righe fattura" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__property_account_expense +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__property_account_expense +msgid "Default Expense Account" +msgstr "Conto di costo predefinito" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_partner__property_account_income +#: model:ir.model.fields,field_description:account_invoice_line_default_account.field_res_users__property_account_income +msgid "Default Income Account" +msgstr "Conto di ricavo predefinito" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__property_account_expense +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__property_account_expense +msgid "Default counterpart account for purchases on invoice lines" +msgstr "Contropartita predefinita per gli acquisti sulle righe fattura" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__property_account_income +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__property_account_income +msgid "Default counterpart account for sales on invoice lines" +msgstr "Contropartita predefinita per le vendite sulle righe fattura" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_account_invoice_line +msgid "Invoice Line" +msgstr "Riga fattura" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__auto_update_account_expense +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__auto_update_account_expense +msgid "When an account is selected on an invoice line, automatically assign it as default expense account" +msgstr "Quando viene selezionato un conto sulla riga fattura, assegnarlo automaticamente come conto di costo predefinito" + +#. module: account_invoice_line_default_account +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_partner__auto_update_account_income +#: model:ir.model.fields,help:account_invoice_line_default_account.field_res_users__auto_update_account_income +msgid "When an account is selected on an invoice line, automatically assign it as default income account" +msgstr "Quando viene selezionato un conto sulla riga fattura, assegnarlo automaticamente come conto di ricavo predefinito" + +#. module: account_invoice_line_default_account +#: model_terms:ir.ui.view,arch_db:account_invoice_line_default_account.view_partner_expense_property_form +msgid "autosave from invoice line" +msgstr "Salvataggio automatico da riga fattura" + diff --git a/account_invoice_line_default_account/i18n/nl.po b/account_invoice_line_default_account/i18n/nl.po new file mode 100644 index 00000000000..2640447a2cb --- /dev/null +++ b/account_invoice_line_default_account/i18n/nl.po @@ -0,0 +1,59 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default_account +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.saas~1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-18 16:01+0000\n" +"PO-Revision-Date: 2013-09-18 16:01+0000\n" +"Last-Translator: Jacques-Etienne Baudoux \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: account_invoice_line_default_account +#: field:res.partner,property_account_expense:0 +msgid "Default Expense Account" +msgstr "Standaard kostenrekening" + +#. module: account_invoice_line_default_account +#: help:res.partner,property_account_expense:0 +msgid "Default counterpart account for purchases on invoice lines" +msgstr "Standaard tegenrekening voor inkoop factuur lijnen" + +#. module: account_invoice_line_default_account +#: help:res.partner,auto_update_account_expense:0 +msgid "When an account is selected on an invoice line, automatically assign it as default expense account" +msgstr "Wanneer een rekening op een factuur lijn is geselecteerd, automatisch toewijzen als standaard kostenrekening" + +#. module: account_invoice_line_default_account +#: code:addons/account_invoice_line_default_account/model/account_invoice_line.py:27 +#: code:addons/account_invoice_line_default_account/model/account_invoice_line.py:47 +#, python-format +msgid "No object created for partner %d" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_account_invoice_line +msgid "Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: view:res.partner:0 +msgid "autosave from invoice line" +msgstr "automatisch bewaren" + +#. module: account_invoice_line_default_account +#: field:res.partner,auto_update_account_expense:0 +msgid "Autosave Selection on Invoice Line" +msgstr "" + +#. module: account_invoice_line_default_account +#: model:ir.model,name:account_invoice_line_default_account.model_res_partner +msgid "Partner" +msgstr "" + diff --git a/account_invoice_line_default_account/models/__init__.py b/account_invoice_line_default_account/models/__init__.py new file mode 100644 index 00000000000..d249ce86db8 --- /dev/null +++ b/account_invoice_line_default_account/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_partner +from . import account_invoice_line diff --git a/account_invoice_line_default_account/models/account_invoice_line.py b/account_invoice_line_default_account/models/account_invoice_line.py new file mode 100644 index 00000000000..d6cc8bb9cf9 --- /dev/null +++ b/account_invoice_line_default_account/models/account_invoice_line.py @@ -0,0 +1,62 @@ +# Copyright 2012 Therp BV () +# Copyright 2013-2018 BCIM SPRL () +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountInvoiceLine(models.Model): + _inherit = 'account.invoice.line' + + @api.onchange('product_id') + def _onchange_product_id(self): + res = super(AccountInvoiceLine, self)._onchange_product_id() + # Return early if line's account does not have to be updated + if self.product_id: + # There is a product that might have set the accounts + return res + + partner = self.invoice_id.partner_id + invoice_type = self.invoice_id.type + if partner and invoice_type: + if invoice_type in ['in_invoice', 'in_refund']: + if partner.property_account_expense: + self.account_id = partner.property_account_expense.id + elif invoice_type in ['out_invoice', 'out_refund']: + if partner.property_account_income: + self.account_id = partner.property_account_income.id + return res + + @api.onchange('account_id') + def _onchange_default_partner_account(self): + # Return early if partner's account does not have to be updated + if not self.account_id or not self.partner_id or self.product_id: + # There is no account, no partner to save the accounts into, + # or there is a product that might have set the accounts + return + if self.env.context.get('journal_id'): + journal = self.env['account.journal'].browse( + self.env.context.get('journal_id')) + if self.account_id in [ + journal.default_credit_account_id, + journal.default_debit_account_id]: + # The account has been set by the journal + return + + # We have a manually entered account_id (no product_id, so the + # account_id is not the result of a product selection). + # Store this account_id as future default in res_partner. + # `write`ing in an onchange is bad, + # but `update`ing the partner does not work. + inv_type = self.env.context.get('type', 'out_invoice') + if (inv_type in ['in_invoice', 'in_refund'] and + self.partner_id.auto_update_account_expense): + if self.account_id != self.partner_id.property_account_expense: + self.partner_id.write({ + 'property_account_expense': self.account_id.id}) + elif (inv_type in ['out_invoice', 'out_refund'] and + self.partner_id.auto_update_account_income): + if self.account_id != self.partner_id.property_account_income: + self.partner_id.write({ + 'property_account_income': self.account_id.id}) diff --git a/account_invoice_line_default_account/models/res_partner.py b/account_invoice_line_default_account/models/res_partner.py new file mode 100644 index 00000000000..80ac120aebb --- /dev/null +++ b/account_invoice_line_default_account/models/res_partner.py @@ -0,0 +1,39 @@ +# Copyright 2012 Therp BV () +# Copyright 2013-2018 BCIM SPRL () +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + property_account_income = fields.Many2one( + 'account.account', + string='Default Income Account', + domain=lambda model: [ + ('user_type_id', '=', + model.env.ref('account.data_account_type_revenue').id), + ], + help='Default counterpart account for sales on invoice lines', + company_dependent=True) + auto_update_account_income = fields.Boolean( + 'Autosave Selection for Income Account on Invoice Line', + help='When an account is selected on an invoice line, ' + 'automatically assign it as default income account', + default=True) + property_account_expense = fields.Many2one( + 'account.account', + string='Default Expense Account', + domain=lambda model: [ + ('user_type_id', '=', + model.env.ref('account.data_account_type_expenses').id), + ], + help='Default counterpart account for purchases on invoice lines', + company_dependent=True) + auto_update_account_expense = fields.Boolean( + 'Autosave Selection for Expense Account on Invoice Line', + help='When an account is selected on an invoice line, ' + 'automatically assign it as default expense account', + default=True) diff --git a/account_invoice_line_default_account/readme/CONTRIBUTORS.rst b/account_invoice_line_default_account/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..3800d985d0c --- /dev/null +++ b/account_invoice_line_default_account/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Ronald Portier, Therp +* Jacques-Etienne Baudoux (BCIM sprl) +* `TAKOBI `_: + + * Simone Rubino + * Lorenzo Battistini diff --git a/account_invoice_line_default_account/readme/DESCRIPTION.rst b/account_invoice_line_default_account/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..cd8fdf3e280 --- /dev/null +++ b/account_invoice_line_default_account/readme/DESCRIPTION.rst @@ -0,0 +1,12 @@ +When entering sales or purchase invoices directly, the user has to select an +account which will be used as a counterpart in the generated move lines. Each +supplier will mostly be linked to one account. For instance when ordering paper +from a supplier that deals in paper, the counterpart account will mostly be +something like 'office expenses'. The same principle has been applied for +customers. This module will add a default counterpart expense and income +account to a partner, comparable to the similiar field in product. When an +invoice is entered, withouth a product, the field from partner will be used as +default. Also when an account is entered on an invoice line (not automatically +selected for a product), the account will be automatically linked to the +partner as default expense or income account, unless explicitly disabled in the +partner record. diff --git a/account_invoice_line_default_account/readme/ROADMAP.rst b/account_invoice_line_default_account/readme/ROADMAP.rst new file mode 100644 index 00000000000..c0503e1dbcd --- /dev/null +++ b/account_invoice_line_default_account/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +- Remove the `write` from `account.invoice.line._onchange_account_id` +- Retrieve the real `default` attribute for field `account.invoice.line.account_id` diff --git a/account_invoice_line_default_account/static/description/index.html b/account_invoice_line_default_account/static/description/index.html new file mode 100644 index 00000000000..2332ad19e49 --- /dev/null +++ b/account_invoice_line_default_account/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Account Invoice Line Default Account + + + +
+

Account Invoice Line Default Account

+ + +

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runbot

+

When entering sales or purchase invoices directly, the user has to select an +account which will be used as a counterpart in the generated move lines. Each +supplier will mostly be linked to one account. For instance when ordering paper +from a supplier that deals in paper, the counterpart account will mostly be +something like ‘office expenses’. The same principle has been applied for +customers. This module will add a default counterpart expense and income +account to a partner, comparable to the similiar field in product. When an +invoice is entered, withouth a product, the field from partner will be used as +default. Also when an account is entered on an invoice line (not automatically +selected for a product), the account will be automatically linked to the +partner as default expense or income account, unless explicitly disabled in the +partner record.

+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • Remove the write from account.invoice.line._onchange_account_id
  • +
  • Retrieve the real default attribute for field account.invoice.line.account_id
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
  • BCIM
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/account-invoicing project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_invoice_line_default_account/tests/__init__.py b/account_invoice_line_default_account/tests/__init__.py new file mode 100644 index 00000000000..165ff0133f6 --- /dev/null +++ b/account_invoice_line_default_account/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_default_account diff --git a/account_invoice_line_default_account/tests/test_default_account.py b/account_invoice_line_default_account/tests/test_default_account.py new file mode 100644 index 00000000000..0006238557e --- /dev/null +++ b/account_invoice_line_default_account/tests/test_default_account.py @@ -0,0 +1,112 @@ +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo.addons.account.tests.account_test_users import AccountTestUsers +from odoo.fields import first +from odoo.tests import tagged, Form + + +@tagged('post_install', '-at_install') +class TestDefaultAccount (AccountTestUsers): + + def _create_invoice(self, user, partner, product=None): + account_invoice_model = self.account_invoice_model + if user: + account_invoice_model = account_invoice_model.sudo(user.id) + + invoice_form = Form(account_invoice_model) + invoice_form.partner_id = partner + with invoice_form.invoice_line_ids.new() as line: + if product: + line.product_id = product + else: + # Required for invoice lines + line.name = "Test line" + + return invoice_form.save() + + def setUp(self): + super().setUp() + self.partner = self.env.ref('base.res_partner_3') + self.account_invoice_model = self.env['account.invoice'] \ + .sudo(self.account_user.id) + self.product = self.env.ref('product.product_product_5') + + self.invoice = self._create_invoice( + self.account_user, + self.partner, + ) + invoice_line = first(self.invoice.invoice_line_ids) + self.default_account = invoice_line.account_id + self.partner_account = self.default_account.search([ + ('id', '!=', self.default_account.id), + ], + limit=1, + ) + + def test_default_account_product(self): + """ + If the invoice line has a product, account is not changed + """ + # Arrange: Set a different account in the partner + self.partner.property_account_income = self.partner_account + self.assertNotEqual(self.default_account, self.partner_account) + + # Act: Create an invoice + invoice = self._create_invoice( + self.account_user, + self.partner, + self.product, + ) + invoice_line = first(invoice.invoice_line_ids) + + # Assert: Account in the line is not changed + self.assertEqual(invoice_line.account_id, self.default_account) + + def test_default_account_no_product(self): + """ + If the invoice line has no product, account is changed + """ + # Arrange: Set a different account in the partner + self.partner.property_account_income = self.partner_account + self.assertNotEqual(self.default_account, self.partner_account) + + # Act: Create an invoice without product + invoice = self._create_invoice( + self.account_user, + self.partner, + ) + invoice_line = first(invoice.invoice_line_ids) + + # Assert: Account in the line is what was set in the partner + self.assertEqual(invoice_line.account_id, self.partner_account) + + def test_default_account_autosave(self): + """ + If the partner is configured to save the updated account, it is saved. + """ + # Arrange: Set a different account in the partner + self.partner.property_account_income = self.partner_account + self.assertNotEqual(self.default_account, self.partner_account) + used_accounts = self.default_account | self.partner_account + other_account = self.default_account.search([ + ('id', 'not in', used_accounts.ids), + ], + limit=1, + ) + + # pre-condition: Partner is set to save income account + self.assertTrue(self.partner.auto_update_account_income) + + # Act: Edit the account in the line + invoice_form = Form(self.invoice) + with invoice_form.invoice_line_ids.edit(0) as line: + line.account_id = other_account + invoice_form.save() + + # Assert: Account in the line has been set in the partner + self.assertEqual( + self.partner.property_account_income, + other_account, + ) diff --git a/account_invoice_line_default_account/views/res_partner.xml b/account_invoice_line_default_account/views/res_partner.xml new file mode 100644 index 00000000000..14c07bf95d2 --- /dev/null +++ b/account_invoice_line_default_account/views/res_partner.xml @@ -0,0 +1,40 @@ + + + + + + res.partner.property.form.inherit + res.partner + form + + + + + + + + + diff --git a/setup/account_invoice_line_default_account/odoo/addons/account_invoice_line_default_account b/setup/account_invoice_line_default_account/odoo/addons/account_invoice_line_default_account new file mode 120000 index 00000000000..394a1595b72 --- /dev/null +++ b/setup/account_invoice_line_default_account/odoo/addons/account_invoice_line_default_account @@ -0,0 +1 @@ +../../../../account_invoice_line_default_account \ No newline at end of file diff --git a/setup/account_invoice_line_default_account/setup.py b/setup/account_invoice_line_default_account/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_invoice_line_default_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)