Merge lp:~vauxoo/openerp-venezuela-localization/7.0-lp1251135_wh_src-dev-hbto into lp:~vauxoo/openerp-venezuela-localization/7.0-lp1251135_wh_core-dev-hbto

Proposed by hbto [Vauxoo] http://www.vauxoo.com
Status: Merged
Approved by: hbto [Vauxoo] http://www.vauxoo.com
Approved revision: 955
Merged at revision: 950
Proposed branch: lp:~vauxoo/openerp-venezuela-localization/7.0-lp1251135_wh_src-dev-hbto
Merge into: lp:~vauxoo/openerp-venezuela-localization/7.0-lp1251135_wh_core-dev-hbto
Diff against target: 442 lines (+195/-77)
5 files modified
l10n_ve_withholding_src/model/invoice.py (+28/-12)
l10n_ve_withholding_src/model/wh_src.py (+105/-35)
l10n_ve_withholding_src/report/wh_src_report.py (+5/-5)
l10n_ve_withholding_src/view/wh_src_view.xml (+43/-21)
l10n_ve_withholding_src/workflow/l10n_ve_wh_src_wf.xml (+14/-4)
To merge this branch: bzr merge lp:~vauxoo/openerp-venezuela-localization/7.0-lp1251135_wh_src-dev-hbto
Reviewer Review Type Date Requested Status
hbto [Vauxoo] http://www.vauxoo.com Pending
Review via email: mp+198589@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_ve_withholding_src/model/invoice.py'
2--- l10n_ve_withholding_src/model/invoice.py 2013-11-18 04:14:18 +0000
3+++ l10n_ve_withholding_src/model/invoice.py 2013-12-11 15:35:19 +0000
4@@ -41,19 +41,17 @@
5 @param partner_bank_id: Partner bank id of the invoice
6 @param company_id: Company id
7 """
8- p = self.pool.get('res.partner').browse(cr, uid, partner_id)
9- u= self.pool.get('res.users').browse(cr, uid, uid)
10- c = u.company_id.partner_id
11+ rp_obj = self.pool.get('res.partner')
12 res = super(account_invoice,self).onchange_partner_id(cr, uid, ids, type, \
13 partner_id, date_invoice,payment_term,partner_bank_id,company_id)
14
15- if p.wh_src_agent and type in ('out_invoice') and not p.supplier:
16- res['value']['wh_src_rate'] = p.wh_src_rate
17- elif c.wh_src_agent and type in ('in_invoice') and p.supplier:
18- res['value']['wh_src_rate'] = c.wh_src_rate
19+ if type in ('out_invoice',):
20+ p = rp_obj._find_accounting_partner(rp_obj.browse(cr, uid, partner_id))
21+ res['value']['wh_src_rate'] = p.wh_src_agent and p.wh_src_rate or 0
22 else:
23- res['value']['wh_src_rate'] = 0
24-
25+ u= self.pool.get('res.users').browse(cr, uid, uid)
26+ c = rp_obj._find_accounting_partner(u.company_id.partner_id)
27+ res['value']['wh_src_rate'] = c.wh_src_agent and c.wh_src_rate or 0
28 return res
29
30 def _retenida(self, cr, uid, ids, name, args, context):
31@@ -143,9 +141,10 @@
32 pay_journal_id, writeoff_acc_id,
33 writeoff_period_id, writeoff_journal_id, date,
34 name, context=context)
35+ rp_obj = self.pool.get('res.partner')
36 if context.get('wh_src',False):
37 invoice = self.browse(cr, uid, ids[0])
38-
39+ acc_part_brw = rp_obj._find_accounting_partner(invoice.partner_id)
40 types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
41 direction = types[invoice.type]
42
43@@ -155,15 +154,32 @@
44 else:
45 acc = tax_brw.wh_id.company_id.wh_src_paid_account_id and tax_brw.wh_id.company_id.wh_src_paid_account_id.id or False
46 if not acc:
47- raise osv.except_osv(_('Missing Account in Tax!'),_("Tax [%s] has missing account. Please, fill the missing fields") % (tax_brw.wh_id.company_id.name,))
48+ raise osv.except_osv(_('Missing Account in Company!'),_("Your Company [%s] has missing account. Please, fill the missing fields") % (tax_brw.wh_id.company_id.name,))
49 res.append((0,0,{
50 'debit': direction * tax_brw.wh_amount<0 and - direction * tax_brw.wh_amount,
51 'credit': direction * tax_brw.wh_amount>0 and direction * tax_brw.wh_amount,
52 'account_id': acc,
53- 'partner_id': invoice.partner_id.id,
54+ 'partner_id': acc_part_brw.id,
55 'ref':invoice.number,
56 'date': date,
57 'currency_id': False,
58 'name':name
59 }))
60 return res
61+
62+ def action_cancel(self, cr, uid, ids, context=None):
63+ """ Verify first if the invoice have a non cancel src withholding doc.
64+ If it has then raise a error message. """
65+ context = context or {}
66+ for inv_brw in self.browse(cr, uid, ids, context=context):
67+ if not inv_brw.wh_src_id:
68+ super(account_invoice, self).action_cancel(cr, uid, ids,
69+ context=context)
70+ else:
71+ raise osv.except_osv(_("Error!"),
72+ _("You can't cancel an invoice that have non cancel"
73+ " Src Withholding Document. Needs first cancel the invoice"
74+ " Src Withholding Document and then you can cancel this"
75+ " invoice."))
76+ return True
77+
78
79=== modified file 'l10n_ve_withholding_src/model/wh_src.py'
80--- l10n_ve_withholding_src/model/wh_src.py 2013-12-03 15:04:59 +0000
81+++ l10n_ve_withholding_src/model/wh_src.py 2013-12-11 15:35:19 +0000
82@@ -58,26 +58,27 @@
83 return false in otherwise
84 """
85 context = context or {}
86- user_wh_agent = self.pool.get('res.users').browse(cr, uid, uid, context = context).company_id.partner_id.wh_src_agent
87- return user_wh_agent
88+ rp_obj = self.pool.get('res.partner')
89+ ru_obj = self.pool.get('res.users')
90+ ru_brw = ru_obj.browse(cr, uid, uid, context = context)
91+ acc_part_brw = rp_obj._find_accounting_partner(ru_brw.company_id.partner_id)
92+ return acc_part_brw.wh_src_agent
93
94 def _get_partner_agent(self, cr, uid, context=None):
95 """ Return a list of browse partner depending of invoice type
96 """
97- context = context or {}
98-
99 obj_partner = self.pool.get('res.partner')
100-
101- if context.get('type') in ('out_invoice'):
102- partner_ids = obj_partner.search(cr, uid, [('wh_src_agent','=',True)])
103- partner_brw = self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context)
104- else:
105- partner_ids = obj_partner.search(cr, uid, [])
106- partner_brw = self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context)
107-
108- l = map(lambda x: x.id, partner_brw)
109-
110- return l
111+ args = [('parent_id','=',False)]
112+ context = context or {}
113+ res = []
114+
115+ if context.get('type') in ('out_invoice',):
116+ args.append(('wh_src_agent','=',True))
117+ partner_ids = obj_partner.search(cr, uid, args)
118+ if partner_ids:
119+ partner_brw = obj_partner.browse(cr, uid, partner_ids, context=context)
120+ res = map(lambda x: x.id, partner_brw)
121+ return res
122
123 def default_get(self, cr, uid, fields, context=None):
124 """ Update fields uid_wh_agent and partner_list to the create a
125@@ -168,28 +169,34 @@
126 @param partner_id: partner id
127 """
128 if context is None: context = {}
129+ acc_part_brw = False
130 acc_id = False
131 res = {}
132 inv_obj = self.pool.get('account.invoice')
133+ rp_obj = self.pool.get('res.partner')
134 wh_line_obj = self.pool.get('account.wh.src.line')
135
136 if partner_id:
137- p = self.pool.get('res.partner').browse(cr, uid, partner_id)
138+ acc_part_brw = rp_obj._find_accounting_partner(rp_obj.browse(cr, uid, partner_id))
139 if type in ('out_invoice', 'out_refund'):
140- acc_id = p.property_account_receivable and p.property_account_receivable.id or False
141+ acc_id = acc_part_brw.property_account_receivable and acc_part_brw.property_account_receivable.id or False
142 else:
143- acc_id = p.property_account_payable and p.property_account_payable.id or False
144-
145- wh_lines = ids and wh_line_obj.search(cr, uid, [('wh_id', '=', ids[0])]) or False
146- p_id_prv = ids and self.browse(cr, uid, ids[0], context=context).partner_id.id or False
147- if wh_lines and p_id_prv != partner_id:
148- wh_line_obj.unlink(cr, uid, wh_lines)
149-
150- res = {'value': {
151- 'account_id': acc_id,
152- }
153+ acc_id = acc_part_brw.property_account_payable and acc_part_brw.property_account_payable.id or False
154+
155+ part_brw = ids and rp_obj._find_accounting_partner(self.browse(cr, uid, ids[0], context=context).partner_id)
156+ wh_lines = ids and wh_line_obj.search(cr, uid, [('wh_id', '=', ids[0])])
157+ if not partner_id:
158+ wh_lines and wh_line_obj.unlink(cr, uid, wh_lines)
159+ wh_lines = []
160+ if part_brw and acc_part_brw and part_brw.id != acc_part_brw.id:
161+ wh_lines and wh_line_obj.unlink(cr, uid, wh_lines)
162+ wh_lines = []
163+
164+ return {'value': {
165+ 'line_ids':wh_lines,
166+ 'account_id': acc_id,
167+ }
168 }
169- return res
170
171
172 def action_date_ret(self,cr,uid,ids,context=None):
173@@ -255,12 +262,65 @@
174
175 return self.write(cr,uid,ids,{'state':'done'})
176
177- def action_cancel(self,cr,uid,ids,context={}):
178- """ Still not allowed to cancel these withholdings
179- """
180- raise osv.except_osv(_('Invalid Procedure!'),_("For the moment, the systmen does not allow cancell these withholdings."))
181- return True
182-
183+ def _dummy_cancel_check(self, cr, uid, ids, context=None):
184+ '''
185+ This will be the method that another developer should use to create new
186+ check on Withholding Document
187+ Make super to this method and create your own cases
188+ '''
189+ return True
190+
191+ def cancel_check(self, cr, uid, ids, context=None):
192+ '''
193+ Unique method to check if we can cancel the Withholding Document
194+ '''
195+ context = context or {}
196+ ids = isinstance(ids, (int, long)) and [ids] or ids
197+
198+ if not self._dummy_cancel_check(cr, uid, ids, context=context):
199+ return False
200+ return True
201+
202+ def cancel_move(self,cr,uid,ids, *args):
203+ """ Delete move lines related with withholding vat and cancel
204+ """
205+ ids = isinstance(ids, (int, long)) and [ids] or ids
206+ am_obj = self.pool.get('account.move')
207+ for ret in self.browse(cr, uid, ids):
208+ if ret.state == 'done':
209+ for ret_line in ret.line_ids:
210+ ret_line.move_id and am_obj.button_cancel(cr, uid, [ret_line.move_id.id])
211+ ret_line.move_id and am_obj.unlink(cr, uid,[ret_line.move_id.id])
212+ ret.write({'state':'cancel'})
213+ return True
214+
215+ def clear_wh_lines(self, cr, uid, ids, context=None):
216+ """ Clear lines of current withholding document and delete wh document
217+ information from the invoice.
218+ """
219+ context = context or {}
220+ awsl_obj = self.pool.get('account.wh.src.line')
221+ ai_obj = self.pool.get('account.invoice')
222+ if ids:
223+ awsl_ids = awsl_obj.search(cr, uid, [('wh_id', 'in', ids)],
224+ context=context)
225+ ai_ids = awsl_ids and [ awsl.invoice_id.id
226+ for awsl in awsl_obj.browse(cr, uid, awsl_ids, context=context) ]
227+ ai_ids and ai_obj.write(cr, uid, ai_ids,
228+ {'wh_src_id': False}, context=context)
229+ awsl_ids and awsl_obj.unlink(cr, uid, awsl_ids, context=context)
230+
231+ return True
232+
233+ def action_cancel(self, cr, uid, ids, context=None):
234+ """ Call cancel_move and return True
235+ """
236+ ids = isinstance(ids, (int, long)) and [ids] or ids
237+ context = context or {}
238+ self.cancel_move(cr, uid, ids)
239+ self.clear_wh_lines(cr, uid, ids, context=context)
240+ return True
241+
242 def copy(self,cr,uid,id,default,context=None):
243 """ Lines can not be duplicated in this model
244 """
245@@ -302,7 +362,17 @@
246 if not period_id:
247 per_obj = self.pool.get('account.period')
248 period_id = per_obj.find(cr, uid,ret.date_ret or time.strftime('%Y-%m-%d'))
249- period_id = per_obj.search(cr,uid,[('id','in',period_id),('special','=',False)])
250+ #Due to the fact that demo data for periods sets 'special' as True on them, this little
251+ #hack is necesary if this issue is solved we should ask directly for the
252+ #refer to this bug for more information
253+ #https://bugs.launchpad.net/openobject-addons/+bug/924200
254+ demo_enabled = self.pool.get('ir.module.module').search(cr, uid,
255+ [('name', '=', 'base'),
256+ ('demo', '=', True)])
257+ args = [('id','in',period_id)]
258+ if not demo_enabled:
259+ args.append(('special','=',False))
260+ period_id = per_obj.search(cr,uid,args)
261 if not period_id:
262 raise osv.except_osv(_('Missing Periods!'),\
263 _("There are not Periods created for the pointed day: %s!") %\
264
265=== modified file 'l10n_ve_withholding_src/report/wh_src_report.py'
266--- l10n_ve_withholding_src/report/wh_src_report.py 2013-04-12 20:19:03 +0000
267+++ l10n_ve_withholding_src/report/wh_src_report.py 2013-12-11 15:35:19 +0000
268@@ -21,10 +21,11 @@
269 def get_empresa(self, partner_id):
270 """ Get information company
271 """
272- obj_addr = self.pool.get('res.partner')
273- res = {}
274- for row in obj_addr.browse(self.cr, self.uid, partner_id):
275- res = row.type == 'invoice' and {
276+ partner_id = isinstance(partner_id, (int,long)) and [partner_id] or partner_id
277+ rp_obj = self.pool.get('res.partner')
278+ row = rp_obj.browse(self.cr, self.uid, partner_id[0])
279+ row = rp_obj._find_accounting_partner(row)
280+ return {
281 'street':row.street,
282 'phone':row.phone,
283 'fax':row.fax,
284@@ -33,7 +34,6 @@
285 'name':row.name,
286 'country':row.country_id.name,
287 }
288- return res
289
290 report_sxw.report_sxw('report.wh.src.report',
291 'account.wh.src',
292
293=== modified file 'l10n_ve_withholding_src/view/wh_src_view.xml'
294--- l10n_ve_withholding_src/view/wh_src_view.xml 2013-12-03 14:25:17 +0000
295+++ l10n_ve_withholding_src/view/wh_src_view.xml 2013-12-11 15:35:19 +0000
296@@ -14,7 +14,10 @@
297 <field name="arch" type="xml">
298 <tree string="Social Responsibility Commitment Withholding Lines" editable="bottom">
299 <field name="name"/>
300- <field name="invoice_id" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)" domain="[('wh_src_id', '=', False),('state', '=', 'open'),('partner_id','=',parent.partner_id),]"/>
301+ <field
302+ name="invoice_id"
303+ on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)"
304+ domain="[('wh_src_id', '=', False),('state', '=', 'open'),'|',('partner_id','=',parent.partner_id),('partner_id','child_of',parent.partner_id)]"/>
305 <field name="base_amount" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)" sum="Total Base a Retener"/>
306 <field name="wh_src_rate" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)"/>
307 <field name="wh_amount" sum="Total Retenido"/>
308@@ -30,7 +33,10 @@
309 <form string="Social Responsibility Commitment Withholding Lines" version="7.0">
310 <notebook>
311 <page string="Linea">
312- <field name="invoice_id" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)" domain="[('wh_src_id', '=', False),('state', '=', 'open'),('partner_id','=',parent.partner_id),]"/>
313+ <field
314+ name="invoice_id"
315+ on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)"
316+ domain="[('wh_src_id', '=', False),('state', '=', 'open'),'|', ('partner_id','=',parent.partner_id), ('partner_id','child_of',parent.partner_id)]"/>
317 <field colspan="4" name="name" select="1"/>
318 <field name="base_amount" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)"/>
319 <field name="wh_src_rate" on_change="onchange_invoice_id(parent.type,invoice_id,base_amount,wh_src_rate)"/>
320@@ -102,13 +108,26 @@
321 <field name="model">account.wh.src</field>
322 <field name="arch" type="xml">
323 <form string="Social Responsibility Commitment Withholding" version="7.0">
324- <field name="uid_wh_agent" invisible="1"/>
325- <field name="partner_list" string="Partners List" context="{'partner_list': partner_list} " invisible="1"/>
326+ <header>
327+ <button name="wh_src_confirmed" states="draft" string="Confirm"/>
328+ <button name="wh_src_done" states="confirmed" string="Done"/>
329+ <button name="wh_src_cancel" states="draft,confirmed,done" string="Cancel"/>
330+ <button name="wh_src_draft" states="cancel,confirmed" string="Set to draft"/>
331+ <field
332+ name="state"
333+ widget="statusbar"
334+ statusbar_visible="draft,confirmed,done"
335+ statusbar_colors="{&quot;confirmed&quot;:&quot;blue&quot;}"/>
336+ </header>
337 <group colspan="4" col="6">
338 <field name="journal_id"/>
339 <field name="type" readonly="1"/>
340 <field name="code"/>
341- <field name="partner_id" on_change="onchange_partner_id(type,partner_id)" attrs="{'readonly':['&amp;',('uid_wh_agent','=',False),('type','=','in_invoice')]}" domain="[('id','in',context.get('partner_list' , False))]"/>
342+ <field
343+ name="partner_id"
344+ on_change="onchange_partner_id(type,partner_id)"
345+ attrs="{'readonly':['|','&amp;',('uid_wh_agent','=',False),('type','=','in_invoice'),('state','!=','draft')]}"
346+ domain="[('id','in',context.get('partner_list' , False))]"/>
347 <field name="currency_id"/>
348 <field name="date_ret"/>
349 <field name="account_id" domain="[('type','=', type == 'in_invoice' and 'payable' or 'receivable'), ('company_id', '=', company_id)]"/>
350@@ -116,27 +135,30 @@
351 <field name="period_id"/>
352 <field name="number" attrs="{'readonly':[('type','=','in_invoice')],'required':[('type','in',['out_invoice','out_refund'])]}"/>
353 <field name="date"/>
354- <field name="wh_amount"/>
355+ <field
356+ name="wh_amount"
357+ attrs="{'readonly':[('state','!=','draft')]}"/>
358 </group>
359 <notebook colspan="4">
360 <page string="Withholding">
361- <field name="line_ids" default_get="{'lines': line_ids }" colspan="4" nolabel="1" height="275">
362-<!--
363- <field name="invoice_id" domain="[('wh_src_id', '!=', False),('state', '=', 'open'), ('partner_id','=',parent.partner_id),]"/>
364--->
365- </field>
366- <group col="4" colspan="2">
367- <field name="state"/>
368- </group>
369- <group col="4" colspan="2">
370- <button name="wh_src_confirmed" states="draft" string="Confirm"/>
371- <button name="wh_src_done" states="confirmed" string="Done"/>
372- <button name="wh_src_cancel" states="done" string="Cancel"/>
373- <button name="wh_src_draft" states="cancel,confirmed" string="Set to draft"/>
374- </group>
375+ <field
376+ name="line_ids"
377+ default_get="{'lines': line_ids }"
378+ colspan="4"
379+ nolabel="1"
380+ height="275"
381+ attrs="{'readonly':[('state','!=','draft')]}"/>
382 </page>
383 <page string="Other Information">
384- <field name="company_id"/>
385+ <field
386+ name="company_id"
387+ attrs="{'readonly':[('state','!=','draft')]}"/>
388+ <field name="uid_wh_agent" invisible="1"/>
389+ <field
390+ name="partner_list"
391+ string="Partners List"
392+ context="{'partner_list': partner_list} "
393+ invisible="1"/>
394 </page>
395 </notebook>
396 </form>
397
398=== modified file 'l10n_ve_withholding_src/workflow/l10n_ve_wh_src_wf.xml'
399--- l10n_ve_withholding_src/workflow/l10n_ve_wh_src_wf.xml 2013-05-23 04:34:03 +0000
400+++ l10n_ve_withholding_src/workflow/l10n_ve_wh_src_wf.xml 2013-12-11 15:35:19 +0000
401@@ -26,8 +26,7 @@
402
403 <record id="act_cancel" model="workflow.activity">
404 <field name="wkf_id" ref="wh_src_wkf"/>
405- <field name="action">action_cancel()
406- write({'state':'cancel'})</field>
407+ <field name="action">action_cancel()</field>
408 <field name="kind">function</field>
409 <field name="name">cancel</field>
410 </record>
411@@ -39,12 +38,23 @@
412 <field name="name">done</field>
413 </record>
414
415-
416 <record id="trans_draft_done" model="workflow.transition">
417 <field name="act_from" ref="act_draft"/>
418 <field name="act_to" ref="act_confirmed"/>
419 <field name="signal">wh_src_confirmed</field>
420 </record>
421+
422+ <record id="trans_confirmed_cancel" model="workflow.transition">
423+ <field name="act_from" ref="act_confirmed"/>
424+ <field name="act_to" ref="act_cancel"/>
425+ <field name="signal">wh_src_cancel</field>
426+ </record>
427+
428+ <record id="trans_draft_cancel" model="workflow.transition">
429+ <field name="act_from" ref="act_draft"/>
430+ <field name="act_to" ref="act_cancel"/>
431+ <field name="signal">wh_src_cancel</field>
432+ </record>
433
434 <record id="trans_done_cancel" model="workflow.transition">
435 <field name="act_from" ref="act_done"/>
436@@ -72,4 +82,4 @@
437
438
439 </data>
440-</openerp>
441\ No newline at end of file
442+</openerp>

Subscribers

People subscribed via source and target branches

to all changes: