Skip to content

Commit

Permalink
[MIG] account_invoice_line_default_account: Migration to 12.0
Browse files Browse the repository at this point in the history
This module is not compatible with account_invoice_line_sequence because them both add to the context of invoice lines in invoice form view
  • Loading branch information
SirTakobi committed May 17, 2022
1 parent 42608c4 commit cf3cc2c
Show file tree
Hide file tree
Showing 15 changed files with 779 additions and 58 deletions.
72 changes: 54 additions & 18 deletions account_invoice_line_default_account/README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

====================================
Account Invoice Line default Account
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
Expand All @@ -19,41 +38,58 @@ 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.

Usage
=====
**Table of contents**

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/95/10.0
.. 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 <https://github.com/OCA/{project_repo}/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/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.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_line_default_account%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Therp BV
* BCIM

Contributors
------------
~~~~~~~~~~~~

* Ronald Portier, Therp
* Jacques-Etienne Baudoux <[email protected]> (BCIM sprl)
* `TAKOBI <https://takobi.online>`_:

* Simone Rubino <[email protected]>

Maintainer
----------
Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit http://odoo-community.org.
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/12.0/account_invoice_line_default_account>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_invoice_line_default_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
7 changes: 5 additions & 2 deletions account_invoice_line_default_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Therp BV (<http://therp.nl>)
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>)
# 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': '10.0.1.0.0',
'version': '12.0.1.0.0',
'depends': [
'account'
],
'excludes': [
'account_invoice_line_sequence',
],
'author': 'Therp BV,BCIM,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'contributors': ['Jacques-Etienne Baudoux <[email protected]>'],
'category': 'Accounting',
'data': [
'views/res_partner.xml',
Expand Down
100 changes: 100 additions & 0 deletions account_invoice_line_default_account/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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-21 14:29+0000\n"
"PO-Revision-Date: 2022-04-21 14:29+0000\n"
"Last-Translator: Simone Rubino <[email protected]>\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_account_invoice_line__account_id
msgid "Account"
msgstr "Conto"

#. module: account_invoice_line_default_account
#: model:ir.model,name:account_invoice_line_default_account.model_account_account_type
msgid "Account Type"
msgstr "Tipo conto"

#. 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 il conto di costo selezionato nella riga 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 il conto di ricavo selezionato nella riga 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 "Conto di contropartita predefinito sulle righe fattura per gli acquisti"

#. 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 "Conto di contropartita predefinito sulle righe fattura per le vendite"

#. 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
#: code:addons/account_invoice_line_default_account/models/account_invoice_line.py:17
#, python-format
msgid "No valid id for context partner_id %d"
msgstr "ID %d non valido per partner_id nel contesto"

#. module: account_invoice_line_default_account
#: model:ir.model.fields,help:account_invoice_line_default_account.field_account_invoice_line__account_id
msgid "The income or expense account related to the selected product."
msgstr "Il conto ricavi o costi relativo al prodotto selezionato."

#. 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 un conto viene selezionato in una riga fattura, viene salvato automaticamente come conto di costo"

#. 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 un conto viene selezionato in una riga fattura, viene salvato automaticamente come conto di ricavo"

#. 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 "Salva automaticamente dalla riga fattura"
2 changes: 1 addition & 1 deletion account_invoice_line_default_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import res_partner
from . import account_invoice_line
27 changes: 17 additions & 10 deletions account_invoice_line_default_account/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Therp BV (<http://therp.nl>)
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>)
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _

Expand All @@ -9,12 +10,12 @@ class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'

def _account_id_default(self):
partner_id = self._context.get('partner_id')
partner_id = self.env.context.get('partner_id')
if not partner_id:
return self._default_account()
assert isinstance(partner_id, int), (
_('No valid id for context partner_id %d') % partner_id)
invoice_type = self._context.get('type')
invoice_type = self.env.context.get('type')
if invoice_type in ['in_invoice', 'in_refund']:
partner = self.env['res.partner'].browse(partner_id)
if partner.property_account_expense:
Expand All @@ -28,20 +29,27 @@ def _account_id_default(self):
account_id = fields.Many2one(default=_account_id_default)

@api.onchange('account_id')
def _onchange_account_id(self):
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:
return super(AccountInvoiceLine, self)._onchange_account_id()
if self._context.get('journal_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._context.get('journal_id'))
self.env.context.get('journal_id'))
if self.account_id in [
journal.default_credit_account_id,
journal.default_debit_account_id]:
return super(AccountInvoiceLine, self)._onchange_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.
inv_type = self._context.get('type', 'out_invoice')
# `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:
Expand All @@ -52,4 +60,3 @@ def _onchange_account_id(self):
if self.account_id != self.partner_id.property_account_income:
self.partner_id.write({
'property_account_income': self.account_id.id})
return super(AccountInvoiceLine, self)._onchange_account_id()
39 changes: 13 additions & 26 deletions account_invoice_line_default_account/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Therp BV (<http://therp.nl>)
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>)
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, fields, api


class AccountAccountType(models.Model):
_inherit = 'account.account.type'

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
# Support xmlid in domain
res = []
if operator == '=':
try:
o = self.env.ref(name)
if o._name == self._name:
res += o.name_get()
except:
pass
if not res:
res = super(AccountAccountType, self).name_search(
name=name, args=args, operator=operator, limit=limit)
return res
from odoo import models, fields


class ResPartner(models.Model):
Expand All @@ -31,22 +12,28 @@ class ResPartner(models.Model):
property_account_income = fields.Many2one(
'account.account',
string='Default Income Account',
domain="[('user_type_id', '=', 'account.data_account_type_revenue')]",
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 on Invoice Line',
'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="[('user_type_id', '=', 'account.data_account_type_expenses')]",
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 on Invoice Line',
'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)
5 changes: 5 additions & 0 deletions account_invoice_line_default_account/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Ronald Portier, Therp
* Jacques-Etienne Baudoux <[email protected]> (BCIM sprl)
* `TAKOBI <https://takobi.online>`_:

* Simone Rubino <[email protected]>
12 changes: 12 additions & 0 deletions account_invoice_line_default_account/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions account_invoice_line_default_account/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -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`
Loading

0 comments on commit cf3cc2c

Please sign in to comment.