Merge lp:~openerp-dev/openobject-addons/trunk-bug-1068038-jco into lp:openobject-addons

Proposed by Josse Colpaert (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-1068038-jco
Merge into: lp:openobject-addons
Diff against target: 341 lines (+100/-44)
5 files modified
account_check_writing/account_voucher.py (+13/-7)
account_voucher/account_voucher.py (+70/-21)
account_voucher/voucher_payment_receipt_view.xml (+13/-12)
hr_expense/hr_expense.py (+3/-3)
hr_expense/hr_expense_view.xml (+1/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-1068038-jco
Reviewer Review Type Date Requested Status
qdp (OpenERP) Pending
Review via email: mp+140942@code.launchpad.net

Description of the change

Company read-only on expense and generating accounting entries checks if the companies of the user and the expense are equal. (raises an exception if not)

To post a comment you must log in.

Unmerged revisions

8425. By Josse Colpaert (OpenERP)

[MERGE] Merge from trunk

8424. By Josse Colpaert (OpenERP)

[MERGE] Merge from bug 1043857

8423. By Josse Colpaert (OpenERP)

[FIX] Expense company is made read-only and a check is put on generating accounting entries

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_check_writing/account_voucher.py'
2--- account_check_writing/account_voucher.py 2012-12-17 15:46:28 +0000
3+++ account_check_writing/account_voucher.py 2012-12-20 16:34:40 +0000
4@@ -19,21 +19,27 @@
5 #
6 ##############################################################################
7
8-from openerp.osv import osv,fields
9-from openerp.tools.translate import _
10-from openerp.tools.amount_to_text_en import amount_to_text
11+from osv import osv,fields
12+from tools.translate import _
13+from tools.amount_to_text_en import amount_to_text
14 from lxml import etree
15
16 class account_voucher(osv.osv):
17 _inherit = 'account.voucher'
18
19- def _make_journal_search(self, cr, uid, ttype, context=None):
20+ def _make_journal_search(self, cr, uid, ttype, company_id = None, context=None):
21 if context is None:
22 context = {}
23 journal_pool = self.pool.get('account.journal')
24 if context.get('write_check',False) :
25- return journal_pool.search(cr, uid, [('allow_check_writing', '=', True)], limit=1)
26- return journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
27+ if company_id is None:
28+ return journal_pool.search(cr, uid, [('allow_check_writing', '=', True)], limit=1)
29+ else:
30+ return journal_pool.search(cr, uid, [('allow_check_writing', '=', True), ('company_id', '=', company_id)])
31+ if company_id is None:
32+ return journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
33+ else:
34+ return journal_pool.search(cr, uid, [('type', '=', ttype), ('company_id', '=', company_id)], limit=1)
35
36 _columns = {
37 'amount_in_word' : fields.char("Amount in Word" , size=128, readonly=True, states={'draft':[('readonly',False)]}),
38@@ -92,7 +98,7 @@
39 nodes = doc.xpath("//field[@name='journal_id']")
40 if context.get('write_check', False) :
41 for node in nodes:
42- node.set('domain', "[('type', '=', 'bank'), ('allow_check_writing','=',True)]")
43+ node.set('domain', "[('type', '=', 'bank'), ('allow_check_writing','=',True), ('company_id', '=', company_id)]")
44 node.set('widget', '')
45 res['arch'] = etree.tostring(doc)
46 return res
47
48=== modified file 'account_voucher/account_voucher.py'
49--- account_voucher/account_voucher.py 2012-12-20 11:47:30 +0000
50+++ account_voucher/account_voucher.py 2012-12-20 16:34:40 +0000
51@@ -22,10 +22,10 @@
52 import time
53 from lxml import etree
54
55-from openerp import netsvc
56-from openerp.osv import fields, osv
57-import openerp.addons.decimal_precision as dp
58-from openerp.tools.translate import _
59+import netsvc
60+from osv import osv, fields
61+import decimal_precision as dp
62+from tools.translate import _
63
64 class res_company(osv.osv):
65 _inherit = "res.company"
66@@ -76,17 +76,23 @@
67 periods = self.pool.get('account.period').find(cr, uid)
68 return periods and periods[0] or False
69
70- def _make_journal_search(self, cr, uid, ttype, context=None):
71+ def _make_journal_search(self, cr, uid, ttype, company_id = None, context=None):
72 journal_pool = self.pool.get('account.journal')
73- return journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
74+ if company_id is None:
75+ return journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
76+ else:
77+ return journal_pool.search(cr, uid, [('type', '=', ttype), ('company_id','=', company_id)])
78
79 def _get_journal(self, cr, uid, context=None):
80 if context is None: context = {}
81 invoice_pool = self.pool.get('account.invoice')
82 journal_pool = self.pool.get('account.journal')
83+ company_id = self._get_company(cr, uid, context=context)
84 if context.get('invoice_id', False):
85 currency_id = invoice_pool.browse(cr, uid, context['invoice_id'], context=context).currency_id.id
86- journal_id = journal_pool.search(cr, uid, [('currency', '=', currency_id)], limit=1)
87+ journal_id = journal_pool.search(cr, uid, ['&', ('company_id','=', company_id), '|',
88+ ('currency', '=', currency_id), '&', ('currency', '=', False),
89+ ('company_id.currency_id', '=', currency_id)], limit=1)
90 return journal_id and journal_id[0] or False
91 if context.get('journal_id', False):
92 return context.get('journal_id')
93@@ -96,8 +102,19 @@
94 ttype = context.get('type', 'bank')
95 if ttype in ('payment', 'receipt'):
96 ttype = 'bank'
97- res = self._make_journal_search(cr, uid, ttype, context=context)
98- return res and res[0] or False
99+ res = self._make_journal_search(cr, uid, ttype, company_id=company_id, context=context)
100+ return res and res[0] or False
101+
102+ def _get_journal_from_company(self, cr, uid, company_id, context=None):
103+ ttype = context.get('type', 'bank')
104+ if ttype in ('payment', 'receipt'):
105+ ttype = 'bank'
106+ if company_id:
107+ res = self._make_journal_search(cr, uid, ttype, company_id=company_id, context=context)
108+ else:
109+ res = False
110+ return res and res[0] or False
111+
112
113 def _get_tax(self, cr, uid, context=None):
114 if context is None: context = {}
115@@ -161,6 +178,13 @@
116 context= {}
117 return context.get('amount', 0.0)
118
119+ def _get_company(self, cr, uid, context=None):
120+ if context is None:
121+ context={}
122+ res = context.get('invoice_id', False) and self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id or (
123+ self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=context))
124+ return res
125+
126 def name_get(self, cr, uid, ids, context=None):
127 if not ids:
128 return []
129@@ -338,6 +362,7 @@
130 'active': True,
131 'period_id': _get_period,
132 'partner_id': _get_partner,
133+ 'company_id': _get_company,
134 'journal_id':_get_journal,
135 'currency_id': _get_currency,
136 'reference': _get_reference,
137@@ -348,7 +373,6 @@
138 'pay_now': 'pay_now',
139 'name': '',
140 'date': lambda *a: time.strftime('%Y-%m-%d'),
141- 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
142 'tax_id': _get_tax,
143 'payment_option': 'without_writeoff',
144 'comment': _('Write-Off'),
145@@ -503,17 +527,41 @@
146 return default
147
148 def onchange_rate(self, cr, uid, ids, rate, amount, currency_id, payment_rate_currency_id, company_id, context=None):
149- res = {'value': {'paid_amount_in_company_currency': amount}}
150- company_currency = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id
151- if rate and amount and currency_id:# and currency_id == payment_rate_currency_id:
152- voucher_rate = self.pool.get('res.currency').browse(cr, uid, currency_id, context).rate
153- if company_currency.id == payment_rate_currency_id:
154- company_rate = rate
155- else:
156- company_rate = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.rate
157- res['value']['paid_amount_in_company_currency'] = amount / voucher_rate * company_rate
158+ if company_id:
159+ res = {'value': {'paid_amount_in_company_currency': amount}}
160+ company_currency = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id
161+ if rate and amount and currency_id: # and currency_id == payment_rate_currency_id:
162+ voucher_rate = self.pool.get('res.currency').browse(cr, uid, currency_id, context).rate
163+ if company_currency.id == payment_rate_currency_id:
164+ company_rate = rate
165+ else:
166+ company_rate = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.rate
167+ res['value']['paid_amount_in_company_currency'] = amount / voucher_rate * company_rate
168+ return res
169+ else:
170+ return {'value': {}}
171+
172+ def onchange_company_id(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, company_id, context=None):
173+ if context is None:
174+ context ={}
175+ if company_id:
176+ if (not journal_id) or (not self.pool.get('account.journal').browse(cr, uid, journal_id, context=context).company_id.id == company_id):
177+ journal_id = self._get_journal_from_company(cr, uid, company_id, context=context)
178+ res = self.onchange_journal(cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, company_id, context)
179+ if not res:
180+ res = {'value': {}}
181+ res['value'].update({'journal_id': journal_id})
182+ ctx = context.copy()
183+ ctx.update({'company_id': company_id})
184+ period_pool = self.pool.get('account.period')
185+ pids = period_pool.find(cr, uid, date, context=ctx)
186+ if pids and pids[0]:
187+ res['value'].update({'period_id': pids[0]})
188+ else:
189+ res = {'value': {'journal_id': False}}
190 return res
191
192+
193 def onchange_amount(self, cr, uid, ids, amount, rate, partner_id, journal_id, currency_id, ttype, date, payment_rate_currency_id, company_id, context=None):
194 if context is None:
195 context = {}
196@@ -611,7 +659,6 @@
197 context_multi_currency = context.copy()
198 if date:
199 context_multi_currency.update({'date': date})
200-
201 currency_pool = self.pool.get('res.currency')
202 move_line_pool = self.pool.get('account.move.line')
203 partner_pool = self.pool.get('res.partner')
204@@ -658,7 +705,9 @@
205 account_type = 'receivable'
206
207 if not context.get('move_line_ids', False):
208- ids = move_line_pool.search(cr, uid, [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)], context=context)
209+ ids = move_line_pool.search(cr, uid, [('state','=','valid'), ('account_id.type', '=', account_type),
210+ ('reconcile_id', '=', False), ('partner_id', '=', partner_id),
211+ ('company_id','=', journal.company_id.id)], context=context)
212 else:
213 ids = context['move_line_ids']
214 invoice_id = context.get('invoice_id', False)
215
216=== modified file 'account_voucher/voucher_payment_receipt_view.xml'
217--- account_voucher/voucher_payment_receipt_view.xml 2012-12-08 10:33:38 +0000
218+++ account_voucher/voucher_payment_receipt_view.xml 2012-12-20 16:34:40 +0000
219@@ -141,9 +141,8 @@
220 <field name="currency_id" invisible="1"/>
221 <field name="amount" invisible="context.get('line_type', False)" on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, payment_rate_currency_id, company_id, context)" class="oe_inline" widget='monetary' options='{"currency_field": "currency_id"}'/>
222 <field name="journal_id"
223- domain="[('type','in',['bank', 'cash'])]"
224+ domain="[('type','in',['bank', 'cash']), ('company_id','=', company_id)]"
225 invisible="context.get('line_type', False)"
226- widget="selection"
227 on_change="onchange_journal(journal_id, line_dr_ids, False, partner_id, date, amount, type, company_id, context)"
228 string="Payment Method"/>
229 </group>
230@@ -151,7 +150,9 @@
231 <field name="date" invisible="context.get('line_type', False)" on_change="onchange_date(date, currency_id, payment_rate_currency_id, amount, company_id, context)"/>
232 <field name="reference" invisible="context.get('line_type', False)" string="Payment Ref" placeholder="e.g. 003/10"/>
233 <field name="name" colspan="2" invisible="context.get('line_type', False)" placeholder="e.g. Invoice SAJ/0042"/>
234- <field name="company_id" widget="selection" groups="base.group_multi_company"/>
235+ <field name="company_id" widget="selection"
236+ on_change="onchange_company_id(journal_id, line_dr_ids, False, partner_id, date, amount, type, company_id, context)"
237+ groups="base.group_multi_company"/>
238 </group>
239 </group>
240 <notebook>
241@@ -292,7 +293,7 @@
242 <group>
243 <group>
244 <field name="state" invisible="1"/>
245- <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" string="Supplier" context="{'search_default_supplier': 1}"/>
246+ <field name="partner_id" string="Customer" required="1" readonly="True"/>
247 <field name="currency_id" invisible="1"/>
248 <field name="amount" class="oe_inline"
249 string="Paid Amount"
250@@ -300,18 +301,17 @@
251 invisible="context.get('line_type', False)"
252 on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, payment_rate_currency_id, company_id, context)"/>
253 <field name="journal_id"
254- domain="[('type','in',['bank', 'cash'])]"
255+ domain="[('type','in',['bank', 'cash']), ('company_id','=',company_id)]"
256 invisible="context.get('line_type', False)"
257- widget="selection"
258 on_change="onchange_journal(journal_id, line_cr_ids, False, partner_id, date, amount, type, company_id, context)"
259 string="Payment Method"/>
260+ <field name="period_id" invisible="1"/>
261 </group>
262 <group>
263 <field name="date" invisible="context.get('line_type', False)" on_change="onchange_date(date, currency_id, payment_rate_currency_id, amount, company_id, context)"/>
264 <field name="reference" invisible="context.get('line_type', False)" string="Payment Ref" placeholder="e.g. 003/10"/>
265 <field name="name" colspan="2" invisible="context.get('line_type', False)" placeholder="e.g. Invoice SAJ/0042"/>
266- <field name="company_id" widget="selection" groups="base.group_multi_company"/>
267-
268+ <field name="company_id" widget="selection" groups="base.group_multi_company" readonly="True"/>
269 <field name="account_id"
270 widget="selection"
271 invisible="True"/>
272@@ -410,8 +410,7 @@
273 widget="monetary" options="{'currency_field': 'currency_id'}"
274 on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, payment_rate_currency_id, company_id, context)"/>
275 <field name="journal_id"
276- domain="[('type','in',['bank', 'cash'])]"
277- widget="selection"
278+ domain="[('type','in',['bank', 'cash']), ('company_id', '=', company_id)]"
279 on_change="onchange_journal(journal_id, line_cr_ids, False, partner_id, date, amount, type, company_id, context)"
280 string="Payment Method"/>
281 </group>
282@@ -419,7 +418,9 @@
283 <field name="date" on_change="onchange_date(date, currency_id, payment_rate_currency_id, amount, company_id, context)"/>
284 <field name="reference" string="Payment Ref" placeholder="e.g. 003/10"/>
285 <field name="name" colspan="2" placeholder="e.g. Invoice SAJ/0042"/>
286- <field name="company_id" widget="selection" groups="base.group_multi_company"/>
287+ <field name="company_id" widget="selection"
288+ on_change="onchange_company_id(journal_id, line_cr_ids, False, partner_id, date, amount, type, company_id, context)"
289+ groups="base.group_multi_company"/>
290
291 <field name="account_id"
292 widget="selection"
293@@ -535,7 +536,7 @@
294 Enter the customer and the payment method and then, either
295 create manually a payment record or OpenERP will propose to you
296 automatically the reconciliation of this payment with the open
297- invoices or sales receipts.
298+ invoices or sales receipts.
299 </p>
300 </field>
301 </record>
302
303=== modified file 'hr_expense/hr_expense.py'
304--- hr_expense/hr_expense.py 2012-12-20 11:47:30 +0000
305+++ hr_expense/hr_expense.py 2012-12-20 16:34:40 +0000
306@@ -126,12 +126,10 @@
307 def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
308 emp_obj = self.pool.get('hr.employee')
309 department_id = False
310- company_id = False
311 if employee_id:
312 employee = emp_obj.browse(cr, uid, employee_id, context=context)
313 department_id = employee.department_id.id
314- company_id = employee.company_id.id
315- return {'value': {'department_id': department_id, 'company_id': company_id}}
316+ return {'value': {'department_id': department_id}}
317
318 def expense_confirm(self, cr, uid, ids, context=None):
319 for expense in self.browse(cr, uid, ids):
320@@ -157,6 +155,8 @@
321 context = {}
322 for exp in self.browse(cr, uid, ids, context=context):
323 company_id = exp.company_id.id
324+ if self.pool.get('res.company')._company_default_get(cr, uid, 'hr_employee', context=context) != company_id:
325+ raise osv.except_osv(_('Wrong company'), _('Please make sure that the company you are working in is the same as that of the expense'))
326 lines = []
327 total = 0.0
328 ctx = context.copy()
329
330=== modified file 'hr_expense/hr_expense_view.xml'
331--- hr_expense/hr_expense_view.xml 2012-12-06 11:12:08 +0000
332+++ hr_expense/hr_expense_view.xml 2012-12-20 16:34:40 +0000
333@@ -76,7 +76,7 @@
334 <field name="employee_id" on_change="onchange_employee_id(employee_id)"/>
335 <field name="date"/>
336 <field name="department_id"/>
337- <field name="company_id" groups="base.group_multi_company"/>
338+ <field name="company_id" readonly="1" groups="base.group_multi_company"/>
339 </group>
340 <group>
341 <field name="name"/>

Subscribers

People subscribed via source and target branches

to all changes: