Merge lp:~therp-nl/account-financial-tools/6.1-account-purchase-default into lp:~account-core-editors/account-financial-tools/6.1

Proposed by Ronald Portier (Therp)
Status: Superseded
Proposed branch: lp:~therp-nl/account-financial-tools/6.1-account-purchase-default
Merge into: lp:~account-core-editors/account-financial-tools/6.1
Diff against target: 223 lines (+191/-0)
6 files modified
account_invoice_line_default_account/__init__.py (+10/-0)
account_invoice_line_default_account/__openerp__.py (+49/-0)
account_invoice_line_default_account/model/__init__.py (+11/-0)
account_invoice_line_default_account/model/account_invoice_line.py (+53/-0)
account_invoice_line_default_account/model/res_partner.py (+34/-0)
account_invoice_line_default_account/view/res_partner_view.xml (+34/-0)
To merge this branch: bzr merge lp:~therp-nl/account-financial-tools/6.1-account-purchase-default
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp Needs Fixing
Stefan Rijnhart (Opener) Needs Fixing
Review via email: mp+145792@code.launchpad.net

This proposal has been superseded by a proposal from 2013-02-01.

Description of the change

Resubmit based on 6.1 branch.

This branch makes it very easy to set the counterpart account to use on a supplier invoice.

For invoices created from purchase orders, or for buying products that are already in the database, this module is not usefull.

But for entering regular invoices for expenses like telecommunication bills, office supplies etc., not having to continually enter the account on which these expenses are to be booked is incredibly usefull and can save huge amounts of time.

This module offers the possibility to manually link a partner (supplier) to an expense account. But even better, it automatically "remembers" the expense account entered for a partner on an invoice - unless explicitly told not to do this.

Module might be extended to also cover manual account move entry. And maybe there is a use for having a similar function on sales invoices as well, altough I reasoned that usually you will sell product in the database, for which you can already set an income account.

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Ronald,

here are my nits:

l.17,42 The module name is not very clear. How about supplier_invoice_default_account?

l.48 Please set 'Therp B.V.' as author, as this prevents multiple 'Therp' entries showing up in the authors sesction of the Apps site and allows people to filter on all our addons by a single click.

l.59..62 init_xml and update_xml are deprecated. Please use the 'data' directive.

l.102 osv.osv is deprecated. Use orm.Model

l.108,109 use "context.get('partner_id')" and "context.get('type')"

l.126 typo 'in_refurd' -> 'in_refund'

l.112,130 You could consider using read() instead of browse(), as it adds less overhead and you only read a single field.

l.203,218 'data' tag at this level no longer necessary from v6.1 on.

review: Needs Fixing
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

l. 53: avoid hyphenation in the module description, as you don't know how the lines will be reformatted when the description is displayed. This is true for docstrings too.

review: Needs Fixing
102. By Ronald Portier (Therp)

[FIX] Update module taking into account reviews bij Stefan Rijnhart (Therp)
      and Alexandre Fayolle (CampToCamp):
      - No hyphenation in module description
      - Better module name
      - Typo's fixed
      - Streamline access to context dictionary: context.get('key')

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Ronald,

you were right about the read/browse performance. Although I get a consistent performance gain of 50% if I do a large number of reads to get a single char field from res.partner when compared to browsing the resource, reading a fields.property using read or a browse record takes almost exactly the same time.

103. By Ronald Portier (Therp)

[FIX] refactored code to make it more mantainable.

104. By Ronald Portier (Therp)

[FIX] Correction of author name.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'account_invoice_line_default_account'
2=== added file 'account_invoice_line_default_account/__init__.py'
3--- account_invoice_line_default_account/__init__.py 1970-01-01 00:00:00 +0000
4+++ account_invoice_line_default_account/__init__.py 2013-02-01 08:03:21 +0000
5@@ -0,0 +1,10 @@
6+# -*- coding: UTF-8 -*-
7+'''
8+Created on 30 jan. 2013
9+
10+@author: Ronald Portier, Therp
11+
12+rportier@therp.nl
13+http://www.therp.nl
14+'''
15+import model
16
17=== added file 'account_invoice_line_default_account/__openerp__.py'
18--- account_invoice_line_default_account/__openerp__.py 1970-01-01 00:00:00 +0000
19+++ account_invoice_line_default_account/__openerp__.py 2013-02-01 08:03:21 +0000
20@@ -0,0 +1,49 @@
21+# -*- coding: utf-8 -*-
22+##############################################################################
23+#
24+# OpenERP, Open Source Management Solution
25+# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
26+#
27+# This program is free software: you can redistribute it and/or modify
28+# it under the terms of the GNU Affero General Public License as
29+# published by the Free Software Foundation, either version 3 of the
30+# License, or (at your option) any later version.
31+#
32+# This program is distributed in the hope that it will be useful,
33+# but WITHOUT ANY WARRANTY; without even the implied warranty of
34+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35+# GNU Affero General Public License for more details.
36+#
37+# You should have received a copy of the GNU Affero General Public License
38+# along with this program. If not, see <http://www.gnu.org/licenses/>.
39+#
40+##############################################################################
41+{
42+ 'name': 'Account Invoice Line Default Account',
43+ 'version': '6.1.r004',
44+ 'depends': [
45+ 'base',
46+ 'account'
47+ ],
48+ 'author': 'Therp B.V.',
49+ 'category': 'Accounting',
50+ 'description': '''When entering purchase invoices directly, the user has
51+to select an account which will be used as a counterpart in the generated
52+move lines. However, each supplier will mostly be linked to one account. For
53+instance when ordering paper from a supplier that deals in paper, the
54+counterpart account will mostly be something like 'office expenses'.
55+This module will add a default counterpart account to a partner (supplier
56+only), comparable to the similiar field in product. When a supplier invoice
57+is entered, withouth a product, the field from partner will be used as default.
58+Also when an expense account is entered on an invoice line (not automatically
59+selectd for a product), the expense account will be automatically linked to
60+the partner - unless explicitly disabled in the partner record.
61+''',
62+ 'data': [
63+ 'view/res_partner_view.xml'
64+ ],
65+ 'demo_xml': [],
66+ 'test': [],
67+ 'installable': True,
68+ 'active': False,
69+}
70
71=== added directory 'account_invoice_line_default_account/model'
72=== added file 'account_invoice_line_default_account/model/__init__.py'
73--- account_invoice_line_default_account/model/__init__.py 1970-01-01 00:00:00 +0000
74+++ account_invoice_line_default_account/model/__init__.py 2013-02-01 08:03:21 +0000
75@@ -0,0 +1,11 @@
76+# -*- coding: UTF-8 -*-
77+'''
78+Created on 30 jan. 2013
79+
80+@author: Ronald Portier, Therp
81+
82+rportier@therp.nl
83+http://www.therp.nl
84+'''
85+import res_partner
86+import account_invoice_line
87
88=== added file 'account_invoice_line_default_account/model/account_invoice_line.py'
89--- account_invoice_line_default_account/model/account_invoice_line.py 1970-01-01 00:00:00 +0000
90+++ account_invoice_line_default_account/model/account_invoice_line.py 2013-02-01 08:03:21 +0000
91@@ -0,0 +1,53 @@
92+# -*- coding: UTF-8 -*-
93+'''
94+Created on 30 jan. 2013
95+
96+@author: Ronald Portier, Therp
97+
98+rportier@therp.nl
99+http://www.therp.nl
100+'''
101+from openerp.osv import orm
102+
103+
104+class account_invoice_line(orm.Model):
105+ _inherit = 'account.invoice.line'
106+
107+ def _account_id_default(self, cr, uid, context=None):
108+ if context is None:
109+ context = {}
110+ partner_id = context.get('partner_id', 0)
111+ invoice_type = context.get('type')
112+ if (partner_id and invoice_type
113+ and invoice_type in ['in_invoice', 'in_refund']):
114+ partner_model = self.pool.get('res.partner')
115+ partner_obj = partner_model.browse(
116+ cr, uid, context['partner_id'], context=context)
117+ if partner_obj and partner_obj['property_account_expense']:
118+ return partner_obj.property_account_expense.id
119+ return False
120+
121+ _defaults = {
122+ 'account_id': _account_id_default,
123+ }
124+
125+ def onchange_account_id(
126+ self, cr, uid, ids, product_id, partner_id, inv_type,
127+ fposition_id, account_id):
128+ if (account_id and partner_id and (not product_id)
129+ and inv_type in ['in_invoice', 'in_refund']):
130+ # We have an account_id, and is not from a product, so
131+ # store it in partner automagically:
132+ partner_model = self.pool.get('res.partner')
133+ partner_obj = partner_model.browse(cr, uid, partner_id)
134+ if partner_obj and partner_obj.auto_update_account_expense:
135+ old_account_id = (
136+ (partner_obj['property_account_expense']
137+ and partner_obj.property_account_expense.id) or 0)
138+ if not account_id == old_account_id:
139+ # only write when something really changed
140+ vals = {'property_account_expense': account_id}
141+ partner_obj.write(vals)
142+ return super(account_invoice_line, self).onchange_account_id(
143+ cr, uid, ids, product_id, partner_id, inv_type,
144+ fposition_id, account_id)
145
146=== added file 'account_invoice_line_default_account/model/res_partner.py'
147--- account_invoice_line_default_account/model/res_partner.py 1970-01-01 00:00:00 +0000
148+++ account_invoice_line_default_account/model/res_partner.py 2013-02-01 08:03:21 +0000
149@@ -0,0 +1,34 @@
150+# -*- coding: UTF-8 -*-
151+'''
152+Created on 30 jan. 2013
153+
154+@author: Ronald Portier, Therp
155+
156+rportier@therp.nl
157+http://www.therp.nl
158+'''
159+from openerp.osv import orm
160+from openerp.osv import fields
161+
162+
163+class res_partner(orm.Model):
164+ _inherit = 'res.partner'
165+
166+ _columns = {
167+ 'property_account_expense': fields.property(
168+ 'account.account',
169+ type='many2one',
170+ relation='account.account',
171+ string='Default expense account',
172+ view_load=True,
173+ domain='''[('user_type.report_type', '=', 'expense')]''',
174+ help='Default counterpart account for purchases',
175+ required=False),
176+ 'auto_update_account_expense': fields.boolean(
177+ 'Save account selected on invoice',
178+ help='When account selected on invoice, automatically save it'),
179+ }
180+
181+ _defaults = {
182+ 'auto_update_account_expense': True,
183+ }
184
185=== added directory 'account_invoice_line_default_account/view'
186=== added file 'account_invoice_line_default_account/view/res_partner_view.xml'
187--- account_invoice_line_default_account/view/res_partner_view.xml 1970-01-01 00:00:00 +0000
188+++ account_invoice_line_default_account/view/res_partner_view.xml 2013-02-01 08:03:21 +0000
189@@ -0,0 +1,34 @@
190+<?xml version="1.0" encoding="utf-8"?>
191+<openerp>
192+ <data>
193+ <record
194+ id="view_partner_expense_property_form"
195+ model="ir.ui.view">
196+ <field name="name">res.partner.property.form.inherit</field>
197+ <field name="model">res.partner</field>
198+ <field name="type">form</field>
199+ <field name="priority">2</field>
200+ <field
201+ name="inherit_id"
202+ ref="account.view_partner_property_form" />
203+ <field
204+ name="arch"
205+ type="xml">
206+ <field
207+ name="property_account_payable"
208+ position="after">
209+ <group
210+ colspan="2"
211+ col="4">
212+ <field
213+ name="property_account_expense"
214+ groups="account.group_account_invoice" />
215+ <field
216+ name="auto_update_account_expense"
217+ groups="account.group_account_invoice" />
218+ </group>
219+ </field>
220+ </field>
221+ </record>
222+ </data>
223+</openerp>

Subscribers

People subscribed via source and target branches