diff --git a/account_invoice_line_default/README.rst b/account_invoice_line_default/README.rst new file mode 100644 index 00000000..101b8144 --- /dev/null +++ b/account_invoice_line_default/README.rst @@ -0,0 +1,13 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +===================== +Invoice Line defaults +===================== + +This module facilitates the encoding of Invoices lines: + +- The 'Account' field is initialised from the default invoice account fields on the partner records. +- The 'Reference/Description' field is moved to the main page of the Supplier Invoice form + and the Invoice Line descriptions are initialised from the Invoice Description field. diff --git a/account_invoice_line_default/__init__.py b/account_invoice_line_default/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_invoice_line_default/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_line_default/__manifest__.py b/account_invoice_line_default/__manifest__.py new file mode 100644 index 00000000..13db005e --- /dev/null +++ b/account_invoice_line_default/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2009-2019 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Invoice Line Defaults', + 'version': '11.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Noviat', + 'website': 'http://www.noviat.com', + 'category': 'Accounting & Finance', + 'complexity': 'normal', + 'summary': 'Account Invoice Line Defaults', + 'data': [ + 'views/account_invoice.xml', + 'views/res_partner.xml', + ], + 'depends': [ + 'account', + ], + 'installable': True +} diff --git a/account_invoice_line_default/i18n/fr.po b/account_invoice_line_default/i18n/fr.po new file mode 100644 index 00000000..53a38e46 --- /dev/null +++ b/account_invoice_line_default/i18n/fr.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: support@noviat.be\n" +"POT-Creation-Date: 2011-09-01 16:38:44.068000\n" +"PO-Revision-Date: 2018-01-05 10:00:00.068000\n" +"Last-Translator: Luc De Meyer (Noviat nv/sa)\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: account_invoice_line_default +#: model:ir.model.fields,field_description:account_invoice_line_default.field_res_partner_property_in_inv_account_id +msgid "Incoming Invoice Account" +msgstr "Compte factures fournisseurs" + +#. module: account_invoice_line_default +#: model:ir.model.fields,field_description:account_invoice_line_default.field_res_partner_property_out_inv_account_id +msgid "Outgoing Invoice Account" +msgstr "Compte factures clients" diff --git a/account_invoice_line_default/i18n/nl.po b/account_invoice_line_default/i18n/nl.po new file mode 100644 index 00000000..1d4fda9a --- /dev/null +++ b/account_invoice_line_default/i18n/nl.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_line_default +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: support@noviat.be\n" +"POT-Creation-Date: 2011-09-01 16:38:44.039000\n" +"PO-Revision-Date: 2018-01-05 10:00:00.039000\n" +"Last-Translator: Luc De Meyer (Noviat nv/sa)\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: nl\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: account_invoice_line_default +#: model:ir.model.fields,field_description:account_invoice_line_default.field_res_partner_property_in_inv_account_id +msgid "Incoming Invoice Account" +msgstr "Rekening Inkoopfacturen" + +#. module: account_invoice_line_default +#: model:ir.model.fields,field_description:account_invoice_line_default.field_res_partner_property_out_inv_account_id +msgid "Outgoing Invoice Account" +msgstr "Rekening Verkoopfacturen" diff --git a/account_invoice_line_default/models/__init__.py b/account_invoice_line_default/models/__init__.py new file mode 100644 index 00000000..7e84281d --- /dev/null +++ b/account_invoice_line_default/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_invoice +from . import res_partner diff --git a/account_invoice_line_default/models/account_invoice.py b/account_invoice_line_default/models/account_invoice.py new file mode 100644 index 00000000..4ed09d30 --- /dev/null +++ b/account_invoice_line_default/models/account_invoice.py @@ -0,0 +1,65 @@ +# Copyright 2009-2019 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo import api, fields, models + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + @api.model + def fields_view_get(self, view_id=None, view_type=False, + toolbar=False, submenu=False): + res = super(AccountInvoice, self).fields_view_get( + view_id=view_id, view_type=view_type, + toolbar=toolbar, submenu=submenu) + context = self._context + if not context.get('account_invoice_line_default'): + if view_type == 'form': + view = etree.XML(res['arch']) + inv_line_ids = view.xpath("//field[@name='invoice_line_ids']") + extra_ctx = ( + "'account_invoice_line_default': 1, " + "'inv_name': name, " + "'inv_partner_id': partner_id") + for el in inv_line_ids: + ctx = el.get('context') + if ctx: + ctx_strip = ctx.rstrip("}").strip().rstrip(",") + ctx = ctx_strip + ", " + extra_ctx + "}" + else: + ctx = "{" + extra_ctx + "}" + el.set('context', str(ctx)) + res['arch'] = etree.tostring(view) + return res + + +class AccountInvoiceLine(models.Model): + _inherit = 'account.invoice.line' + + name = fields.Text( + default=lambda self: self._default_name()) + account_id = fields.Many2one( + default=lambda self: self._default_account()) + + @api.model + def _default_name(self): + return self._context.get('account_invoice_line_default') \ + and self._context.get('inv_name') + + @api.model + def _default_account(self): + ctx = self._context + account = None + if ctx.get('account_invoice_line_default'): + if ctx.get('inv_partner_id'): + partner = self.env['res.partner'].browse( + ctx['inv_partner_id']) + partner = partner.commercial_partner_id + if ctx.get('type') in ['in_invoice', 'in_refund']: + account = partner.property_in_inv_account_id + else: + account = partner.property_out_inv_account_id + return account or super(AccountInvoiceLine, self)._default_account() diff --git a/account_invoice_line_default/models/res_partner.py b/account_invoice_line_default/models/res_partner.py new file mode 100644 index 00000000..dc5e1edd --- /dev/null +++ b/account_invoice_line_default/models/res_partner.py @@ -0,0 +1,23 @@ +# Copyright 2009-2019 Noviat. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + property_in_inv_account_id = fields.Many2one( + comodel_name='account.account', + string='Incoming Invoice Account', + company_dependent=True, + domain=[('deprecated', '=', False)], + oldname="property_in_inv_acc", + help="Default Account on incoming Invoices.") + property_out_inv_account_id = fields.Many2one( + comodel_name='account.account', + string='Outgoing Invoice Account', + company_dependent=True, + domain=[('deprecated', '=', False)], + oldname="property_out_inv_acc", + help="Default Account on outgoing Invoices.") diff --git a/account_invoice_line_default/static/description/icon.png b/account_invoice_line_default/static/description/icon.png new file mode 100644 index 00000000..32740c0c Binary files /dev/null and b/account_invoice_line_default/static/description/icon.png differ diff --git a/account_invoice_line_default/views/account_invoice.xml b/account_invoice_line_default/views/account_invoice.xml new file mode 100644 index 00000000..b5c291ce --- /dev/null +++ b/account_invoice_line_default/views/account_invoice.xml @@ -0,0 +1,18 @@ + + + + + account.invoice.supplier.form.inherit + account.invoice + + + + + + + + + + + + diff --git a/account_invoice_line_default/views/res_partner.xml b/account_invoice_line_default/views/res_partner.xml new file mode 100644 index 00000000..acb4b0b1 --- /dev/null +++ b/account_invoice_line_default/views/res_partner.xml @@ -0,0 +1,18 @@ + + + + + res.partner.property.form.inherit + res.partner + + + + + + + + + + + +