-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_invoice_line_default_account
- Loading branch information
Showing
6 changed files
with
134 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
# -*- coding: UTF-8 -*- | ||
''' | ||
Created on 30 jan. 2013 | ||
|
||
@author: Ronald Portier, Therp | ||
[email protected] | ||
http://www.therp.nl | ||
Ported to 7.0 on Sept. 17, 2013 by Jacques-Etienne Baudoux, BCIM (www.bcim.be) | ||
''' | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2012 Therp BV (<http://therp.nl>) | ||
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>) | ||
# 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', | ||
'depends': [ | ||
'account' | ||
], | ||
'author': 'Therp BV,BCIM,Odoo Community Association (OCA)', | ||
'contributors': ['Jacques-Etienne Baudoux <[email protected]>'], | ||
'category': 'Accounting', | ||
'data': [ | ||
'views/res_partner.xml', | ||
'views/account_invoice.xml', | ||
], | ||
'installable': True, | ||
} |
101 changes: 43 additions & 58 deletions
101
account_invoice_line_default_account/models/account_invoice_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,55 @@ | ||
# -*- coding: UTF-8 -*- | ||
''' | ||
Created on 30 jan. 2013 | ||
# Copyright 2012 Therp BV (<http://therp.nl>) | ||
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>) | ||
|
||
@author: Ronald Portier, Therp | ||
@contributor: Jacques-Etienne Baudoux, BCIM | ||
''' | ||
from odoo import api, fields, models, _ | ||
|
||
from openerp.osv import orm | ||
from openerp.tools.translate import _ | ||
|
||
|
||
class account_invoice_line(orm.Model): | ||
class AccountInvoiceLine(models.Model): | ||
_inherit = 'account.invoice.line' | ||
|
||
def _account_id_default(self, cr, uid, context=None): | ||
if context is None: | ||
context = {} | ||
partner_id = context.get('partner_id') | ||
def _account_id_default(self): | ||
partner_id = self._context.get('partner_id') | ||
if not partner_id: | ||
return False | ||
assert isinstance(partner_id, (int, long)), ( | ||
return self._default_account() | ||
assert isinstance(partner_id, int), ( | ||
_('No valid id for context partner_id %d') % partner_id) | ||
invoice_type = context.get('type') | ||
partner_model = self.pool.get('res.partner') | ||
invoice_type = self._context.get('type') | ||
if invoice_type in ['in_invoice', 'in_refund']: | ||
partner = partner_model.read( | ||
cr, uid, partner_id, | ||
['property_account_expense'], context=context) | ||
return partner['property_account_expense'] | ||
partner = self.env['res.partner'].browse(partner_id) | ||
if partner.property_account_expense: | ||
return partner.property_account_expense.id | ||
elif invoice_type in ['out_invoice', 'out_refund']: | ||
partner = partner_model.read( | ||
cr, uid, partner_id, | ||
['property_account_income'], context=context) | ||
return partner['property_account_income'] | ||
return False | ||
partner = self.env['res.partner'].browse(partner_id) | ||
if partner.property_account_income: | ||
return partner.property_account_income.id | ||
return self._default_account() | ||
|
||
_defaults = { | ||
'account_id': _account_id_default, | ||
} | ||
account_id = fields.Many2one(default=_account_id_default) | ||
|
||
def onchange_account_id( | ||
self, cr, uid, ids, product_id, partner_id, inv_type, | ||
fposition_id, account_id, context=None): | ||
if account_id and partner_id and not product_id: | ||
# 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. | ||
partner_model = self.pool.get('res.partner') | ||
partner = partner_model.read( | ||
cr, uid, partner_id, | ||
['auto_update_account_expense', 'property_account_expense', | ||
'auto_update_account_income', 'property_account_income'], | ||
context=context) | ||
vals = {} | ||
if (inv_type in ['in_invoice', 'in_refund'] and | ||
partner['auto_update_account_expense']): | ||
if account_id != partner['property_account_expense']: | ||
# only write when something really changed | ||
vals.update({'property_account_expense': account_id}) | ||
elif (inv_type in ['out_invoice', 'out_refund'] and | ||
partner['auto_update_account_income']): | ||
if account_id != partner['property_account_income']: | ||
# only write when something really changed | ||
vals.update({'property_account_income': account_id}) | ||
if vals: | ||
partner_model.write(cr, uid, partner_id, vals, context=context) | ||
return super(account_invoice_line, self).onchange_account_id( | ||
cr, uid, ids, product_id, partner_id, inv_type, | ||
fposition_id, account_id) | ||
@api.onchange('account_id') | ||
def _onchange_account_id(self): | ||
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'): | ||
journal = self.env['account.journal'].browse( | ||
self._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() | ||
# 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') | ||
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}) | ||
return super(AccountInvoiceLine, self)._onchange_account_id() |
66 changes: 26 additions & 40 deletions
66
account_invoice_line_default_account/models/res_partner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,32 @@ | ||
# -*- coding: UTF-8 -*- | ||
''' | ||
Created on 30 jan. 2013 | ||
# Copyright 2012 Therp BV (<http://therp.nl>) | ||
# Copyright 2013-2018 BCIM SPRL (<http://www.bcim.be>) | ||
|
||
@author: Ronald Portier, Therp | ||
@contributor: Jacques-Etienne Baudoux, BCIM | ||
''' | ||
from odoo import models, fields | ||
|
||
from openerp.osv import orm | ||
from openerp.osv import fields | ||
|
||
|
||
class res_partner(orm.Model): | ||
class ResPartner(models.Model): | ||
_inherit = 'res.partner' | ||
|
||
_columns = { | ||
'property_account_income': fields.property( | ||
obj_prop='account.account', | ||
type='many2one', | ||
relation='account.account', | ||
string='Default Income Account', | ||
domain='''[('user_type.report_type', '=', 'income')]''', | ||
help='Default counterpart account for sales on invoice lines', | ||
required=False), | ||
'auto_update_account_income': fields.boolean( | ||
'Autosave Selection on Invoice Line', | ||
help='When an account is selected on an invoice line, ' | ||
'automatically assign it as default income account'), | ||
'property_account_expense': fields.property( | ||
obj_prop='account.account', | ||
type='many2one', | ||
relation='account.account', | ||
string='Default Expense Account', | ||
domain='''[('user_type.report_type', '=', 'expense')]''', | ||
help='Default counterpart account for purchases on invoice lines', | ||
required=False), | ||
'auto_update_account_expense': fields.boolean( | ||
'Autosave Selection on Invoice Line', | ||
help='When an account is selected on an invoice line, ' | ||
'automatically assign it as default expense account'), | ||
} | ||
|
||
_defaults = { | ||
'auto_update_account_income': True, | ||
'auto_update_account_expense': True, | ||
} | ||
property_account_income = fields.Many2one( | ||
'account.account', | ||
string='Default Income Account', | ||
domain='''[('user_type_id', '=', 'Income')]''', | ||
help='Default counterpart account for sales on invoice lines', | ||
company_dependent=True) | ||
auto_update_account_income = fields.Boolean( | ||
'Autosave Selection 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', '=', 'Expenses')]''', | ||
help='Default counterpart account for purchases on invoice lines', | ||
company_dependent=True) | ||
auto_update_account_expense = fields.Boolean( | ||
'Autosave Selection on Invoice Line', | ||
help='When an account is selected on an invoice line, ' | ||
'automatically assign it as default expense account', | ||
default=True) |
25 changes: 17 additions & 8 deletions
25
account_invoice_line_default_account/views/account_invoice.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<odoo> | ||
<record id="invoice_form" model="ir.ui.view"> | ||
<field name="name">account.invoice.form.inherit</field> | ||
<field name="name">invoice_line_ids partner context</field> | ||
<field name="model">account.invoice</field> | ||
<field name="type">form</field> | ||
<field name="inherit_id" ref="account.invoice_form" /> | ||
<field name="inherit_id" ref="account.invoice_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_line" position="attributes"> | ||
<attribute name="context">{'partner_id': partner_id, 'type': type}</attribute> | ||
<field name="invoice_line_ids" position="attributes"> | ||
<attribute name="context">{'partner_id': partner_id, 'type': type, 'journal_id': journal_id}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> | ||
<record id="invoice_supplier_form" model="ir.ui.view"> | ||
<field name="name">invoice_line_ids partner context</field> | ||
<field name="model">account.invoice</field> | ||
<field name="type">form</field> | ||
<field name="inherit_id" ref="account.invoice_supplier_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_line_ids" position="attributes"> | ||
<attribute name="context">{'partner_id': partner_id, 'type': type, 'journal_id': journal_id}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
77 changes: 29 additions & 48 deletions
77
account_invoice_line_default_account/views/res_partner.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<record | ||
id="view_partner_expense_property_form" | ||
model="ir.ui.view"> | ||
<field name="name">res.partner.property.form.inherit</field> | ||
<field name="model">res.partner</field> | ||
<field name="type">form</field> | ||
<field name="priority">2</field> | ||
<field | ||
name="inherit_id" | ||
ref="account.view_partner_property_form" /> | ||
<field | ||
name="arch" | ||
type="xml"> | ||
<field | ||
name="property_account_receivable" | ||
position="after"> | ||
<label for="property_account_income" /> | ||
<div> | ||
<field | ||
name="property_account_income" | ||
<odoo> | ||
<record id="view_partner_expense_property_form" model="ir.ui.view"> | ||
<field name="name">res.partner.property.form.inherit</field> | ||
<field name="model">res.partner</field> | ||
<field name="type">form</field> | ||
<field name="inherit_id" ref="account.view_partner_property_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="property_account_receivable_id" position="after"> | ||
<label for="property_account_income" /> | ||
<div> | ||
<field name="property_account_income" groups="account.group_account_invoice" /> | ||
<div style=" white-space: nowrap; "> | ||
<field name="auto_update_account_income" | ||
nolabel="1" | ||
groups="account.group_account_invoice" /> | ||
<div style=" white-space: nowrap; "> | ||
<field | ||
name="auto_update_account_income" | ||
nolabel="1" | ||
groups="account.group_account_invoice" /> | ||
<label for="auto_update_account_income" string="autosave from invoice line"/> | ||
</div> | ||
<label for="auto_update_account_income" string="autosave from invoice line"/> | ||
</div> | ||
</field> | ||
<field | ||
name="property_account_payable" | ||
position="after"> | ||
<label for="property_account_expense" /> | ||
<div> | ||
<field | ||
name="property_account_expense" | ||
</div> | ||
</field> | ||
<field name="property_account_payable_id" position="after"> | ||
<label for="property_account_expense" /> | ||
<div> | ||
<field name="property_account_expense" groups="account.group_account_invoice" /> | ||
<div style=" white-space: nowrap; "> | ||
<field name="auto_update_account_expense" | ||
nolabel="1" | ||
groups="account.group_account_invoice" /> | ||
<div style=" white-space: nowrap; "> | ||
<field | ||
name="auto_update_account_expense" | ||
nolabel="1" | ||
groups="account.group_account_invoice" /> | ||
<label for="auto_update_account_expense" string="autosave from invoice line"/> | ||
</div> | ||
<label for="auto_update_account_expense" string="autosave from invoice line"/> | ||
</div> | ||
</field> | ||
</div> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> | ||
</field> | ||
</record> | ||
</odoo> |