Merge lp:~noviat/openobject-addons/6.1 into lp:openobject-addons/6.1

Proposed by Luc De Meyer (Noviat)
Status: Work in progress
Proposed branch: lp:~noviat/openobject-addons/6.1
Merge into: lp:openobject-addons/6.1
Diff against target: 349 lines (+102/-86)
3 files modified
l10n_be/wizard/l10n_be_account_vat_declaration.py (+35/-22)
l10n_be/wizard/l10n_be_account_vat_declaration_view.xml (+43/-32)
l10n_be/wizard/l10n_be_vat_intra.py (+24/-32)
To merge this branch: bzr merge lp:~noviat/openobject-addons/6.1
Reviewer Review Type Date Requested Status
Xavier ALT (community) Needs Fixing
Review via email: mp+102753@code.launchpad.net

Description of the change

l10n_be 6.0 forward port of intervat corrections.

To post a comment you must log in.
Revision history for this message
Xavier ALT (dex-phx) wrote :

Hi,

Some problems with your MP:

VAT Declaration
---------------
As for v6.1 "osv_memory" are also stored in the DB,

* using table "account_period_rel" for period_ids is wrong because it's already used by "vat_intra" wizard (will raise IntegrityErrors from PostgreSQL).
* removing "period_id" field is acceptable here, because if user doesn't upgrade his DB it won't be able to run wizard normally (NOT NULL constraints will prevent user to save the wizard data).

Is the multiple periods a legal requirement here ? or is it acceptable to live without it on v6.1 ?

VAT Intra
---------
* You could remove the "hack" for exists(), this is not needed anymore on v6.1.

Regards,
Xavier

review: Needs Fixing
lp:~noviat/openobject-addons/6.1 updated
6743. By root <root@oerp61>

vat declaration wizards

Revision history for this message
Luc De Meyer (Noviat) (luc-demeyer) wrote :

Thanks Xavier,

I included your suggestions into https://code.launchpad.net/~noviat/openobject-addons/6.1/+merge/104342.
I have also attached the two files that have been changed to this email since I didn't update my local 6.1 branch before submitting the merge (with as a consequence a huge and meaningless diff file).

Changes:

>> VAT Declaration
>> ---------------
>> * using table "account_period_rel" for period_ids is wrong because it's already used by "vat_intra" wizard (will raise IntegrityErrors from PostgreSQL).

I have renamed the 'account_period_rel' tables into 'vat_declaration_period_rel' and ' vat_intra_period_rel'

>> * removing "period_id" field is acceptable here, because if user doesn't upgrade his DB it won't be able to run wizard normally (NOT NULL constraints will prevent user to save the wizard data).

>> Is the multiple periods a legal requirement here ? or is it acceptable to live without it on v6.1 ?

Yes and we have (at least) two customers running that way.

>> VAT Intra
>> ---------
>> * You could remove the "hack" for exists(), this is not needed anymore on v6.1.

I have removed the 'exists()' hack.

Regards,
Luc

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of Xavier ALT (OpenERP)
Sent: maandag 30 april 2012 13:24
To: <email address hidden>
Subject: Re: [Merge] lp:~noviat/openobject-addons/6.1 into lp:openobject-addons/6.1

Review: Needs Fixing

Hi,

Some problems with your MP:

VAT Declaration
---------------
As for v6.1 "osv_memory" are also stored in the DB,

* using table "account_period_rel" for period_ids is wrong because it's already used by "vat_intra" wizard (will raise IntegrityErrors from PostgreSQL).
* removing "period_id" field is acceptable here, because if user doesn't upgrade his DB it won't be able to run wizard normally (NOT NULL constraints will prevent user to save the wizard data).

Is the multiple periods a legal requirement here ? or is it acceptable to live without it on v6.1 ?

VAT Intra
---------
* You could remove the "hack" for exists(), this is not needed anymore on v6.1.

Regards,
Xavier
--
https://code.launchpad.net/~noviat/openobject-addons/6.1/+merge/102753
Your team Noviat is subscribed to branch lp:~noviat/openobject-addons/6.1.

Unmerged revisions

6743. By root <root@oerp61>

vat declaration wizards

6742. By root <root@oerp61>

l10n_be intervat correction

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_be/wizard/l10n_be_account_vat_declaration.py' (properties changed: -x to +x)
2--- l10n_be/wizard/l10n_be_account_vat_declaration.py 2012-02-13 11:02:14 +0000
3+++ l10n_be/wizard/l10n_be_account_vat_declaration.py 2012-05-02 07:49:19 +0000
4@@ -9,6 +9,7 @@
5 # - support negative balance
6 # - assign amount of tax code 71-72 correclty to grid 71 or 72
7 # - support Noviat tax code scheme
8+# - support multiple accounting periods per VAT declaration
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as
12@@ -41,7 +42,7 @@
13
14 _columns = {
15 'name': fields.char('File Name', size=32),
16- 'period_id': fields.many2one('account.period','Period', required=True),
17+ 'period_ids': fields.many2many('account.period', 'vat_declaration_period_rel', 'acc_id', 'period_id', 'Period (s)', help = 'Select here the period(s) you want to include in your VAT declaration'),
18 'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', domain=[('parent_id', '=', False)], required=True),
19 'msg': fields.text('File created', size=64, readonly=True),
20 'file_save': fields.binary('Save File'),
21@@ -77,6 +78,10 @@
22
23 list_of_tags = ['00','01','02','03','44','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','72','81','82','83','84','85','86','87','88','91']
24 data_tax = self.browse(cr, uid, ids[0])
25+
26+ if not data_tax.period_ids:
27+ raise osv.except_osv(_('Data Insufficient!'),_('Please select at least one Period.'))
28+
29 if data_tax.tax_code_id:
30 obj_company = data_tax.tax_code_id.company_id
31 else:
32@@ -90,22 +95,30 @@
33 tax_code_ids = obj_tax_code.search(cr, uid, [('parent_id','child_of',data_tax.tax_code_id.id), ('company_id','=',obj_company.id)], context=context)
34 ctx = context.copy()
35 data = self.read(cr, uid, ids)[0]
36- ctx['period_id'] = data['period_id'][0]
37- tax_info = obj_tax_code.read(cr, uid, tax_code_ids, ['code','sum_period'], context=ctx)
38+ tax_info = {}
39+ for period_id in data['period_ids']:
40+ ctx['period_id'] = period_id #added context here
41+ tax_period_info = obj_tax_code.read(cr, uid, tax_code_ids, ['code','sum_period'], context=ctx)
42+ for c in tax_period_info:
43+ tax_info.update({c['code']: tax_info.get(c['code'], 0.0) + c['sum_period']})
44
45 name = email = phone = address = post_code = city = country_code = ''
46 name, email, phone, city, post_code, address, country_code = self.pool.get('res.company')._get_default_ad(obj_company.partner_id.address)
47
48- account_period = obj_acc_period.browse(cr, uid, data['period_id'][0], context=context)
49+ account_periods = obj_acc_period.browse(cr, uid, data['period_ids'], context=context)
50 issued_by = vat_no[:2]
51 comments = data['comments'] or ''
52-
53- send_ref = str(obj_company.partner_id.id) + str(account_period.date_start[5:7]) + str(account_period.date_stop[:4])
54+
55+ period_end_dates = sorted([x.date_stop for x in account_periods])
56+ period_start_dates = sorted([x.date_start for x in account_periods])
57+ send_ref = str(obj_company.partner_id.id) + period_end_dates[0][5:7] + period_end_dates[-1][:4]
58
59- starting_month = account_period.date_start[5:7]
60- ending_month = account_period.date_stop[5:7]
61+ starting_month = period_start_dates[0][5:7]
62+ ending_month = period_end_dates[-1][5:7]
63 quarter = str(((int(starting_month) - 1) / 3) + 1)
64-
65+
66+ if not country_code:
67+ raise osv.except_osv(_('Data Insufficient!'),_('No country associated with the company.'))
68 if not email:
69 raise osv.except_osv(_('Data Insufficient!'),_('No email address associated with the company.'))
70 if not phone:
71@@ -124,7 +137,7 @@
72 'send_ref': send_ref,
73 'quarter': quarter,
74 'month': starting_month,
75- 'year': str(account_period.date_stop[:4]),
76+ 'year': period_end_dates[-1][:4],
77 'client_nihil': (data['client_nihil'] and 'YES' or 'NO'),
78 'ask_restitution': (data['ask_restitution'] and 'YES' or 'NO'),
79 'ask_payment': (data['ask_payment'] and 'YES' or 'NO'),
80@@ -166,31 +179,31 @@
81 data_of_file += '\t<ns2:Year>%(year)s</ns2:Year>' % (file_data)
82 data_of_file += '\n\t\t</ns2:Period>\n'
83 data_of_file += '\t\t<ns2:Data>\t'
84+
85+ if tax_info.get('VI') >= 0:
86+ tax_info['71'] = tax_info['VI']
87+ else:
88+ tax_info['72'] = tax_info['VI']
89 cases_list = []
90 for item in tax_info:
91- if item['code'] == '91' and ending_month != 12:
92+ if tax_info['91'] and ending_month != 12:
93 #the tax code 91 can only be send for the declaration of December
94 continue
95- if item['code'] and item['sum_period']:
96- if item['code'] == 'VI':
97- if item['sum_period'] >= 0:
98- item['code'] = '71'
99- else:
100- item['code'] = '72'
101- if item['code'] in list_of_tags:
102- cases_list.append(item)
103+ if tax_info[item] and item in list_of_tags:
104+ cases_list.append(item)
105 cases_list.sort()
106 for item in cases_list:
107 grid_amount_data = {
108- 'code': str(int(item['code'])),
109- 'amount': str(abs(item['sum_period'])),
110+ 'code': str(int(item)),
111+ 'amount': '%.2f' %abs(tax_info[item]),
112 }
113 data_of_file += '\n\t\t\t<ns2:Amount GridNumber="%(code)s">%(amount)s</ns2:Amount''>' % (grid_amount_data)
114
115 data_of_file += '\n\t\t</ns2:Data>'
116 data_of_file += '\n\t\t<ns2:ClientListingNihil>%(client_nihil)s</ns2:ClientListingNihil>' % (file_data)
117 data_of_file += '\n\t\t<ns2:Ask Restitution="%(ask_restitution)s" Payment="%(ask_payment)s"/>' % (file_data)
118- data_of_file += '\n\t\t<ns2:Comment>%(comments)s</ns2:Comment>' % (file_data)
119+ if file_data['comments']:
120+ data_of_file += '\n\t\t<ns2:Comment>%(comments)s</ns2:Comment>' % (file_data)
121 data_of_file += '\n\t</ns2:VATDeclaration> \n</ns2:VATConsignment>'
122 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_vat_save')], context=context)
123 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
124
125=== modified file 'l10n_be/wizard/l10n_be_account_vat_declaration_view.xml' (properties changed: -x to +x)
126--- l10n_be/wizard/l10n_be_account_vat_declaration_view.xml 2012-02-13 11:02:14 +0000
127+++ l10n_be/wizard/l10n_be_account_vat_declaration_view.xml 2012-05-02 07:49:19 +0000
128@@ -2,39 +2,50 @@
129 <openerp>
130 <data>
131
132- <record id="view_vat_declaration" model="ir.ui.view">
133- <field name="name">Vat Declaraion</field>
134- <field name="model">l1on_be.vat.declaration</field>
135- <field name="type">form</field>
136- <field name="arch" type="xml">
137- <form string="Periodical VAT Declaration">
138- <group>
139- <group colspan="4">
140- <separator string="Declare Periodical VAT" colspan="4"/>
141- <field name="period_id" widget="selection"/>
142- <field name="tax_code_id" string="Company" widget="selection" groups="base.group_multi_company"/>
143- <newline/>
144- <separator string="Advanced Options" colspan="4"/>
145- <field name="ask_restitution"/>
146- <field name="ask_payment"/>
147- <field name="client_nihil" string="Is Last Declaration"/><label/>
148- </group>
149- <group colspan="4" groups="base.group_extended">
150- <separator string="Comments" colspan="4"/>
151- <field colspan="4" name="comments" nolabel="1"/>
152- </group>
153- <group>
154- <separator colspan="4"/>
155- <newline/>
156- <button special="cancel" string="Close" icon="gtk-cancel"/>
157- <button icon="gtk-execute" name="create_xml" string="Create XML" type="object" default_focus="1" />
158- </group>
159- </group>
160- </form>
161- </field>
162- </record>
163+ <record id="view_vat_declaration" model="ir.ui.view">
164+ <field name="name">Vat Declaraion</field>
165+ <field name="model">l1on_be.vat.declaration</field>
166+ <field name="type">form</field>
167+ <field name="arch" type="xml">
168+ <form string="Periodical VAT Declaration">
169+ <group>
170+ <group colspan="4">
171+ <separator string="Declare Periodical VAT" colspan="4"/>
172+ <field name="tax_code_id" string="Company" widget="selection" groups="base.group_multi_company"/>
173+ <separator string="Periods" colspan="4"/>
174+ <field name="period_ids" nolabel="1" colspan="4" height="200" width="550">
175+ <tree colors="blue:state in ('draft');gray:state in ('done') " string="Period">
176+ <field name="name"/>
177+ <field name="code"/>
178+ <field name="date_start"/>
179+ <field name="date_stop"/>
180+ <field name="special"/>
181+ <field name="state"/>
182+ </tree>
183+ </field>
184+ <newline/>
185+ <separator string="Advanced Options" colspan="4"/>
186+ <field name="ask_restitution"/>
187+ <field name="ask_payment"/>
188+ <field name="client_nihil" string="Is Last Declaration"/>
189+ <label/>
190+ </group>
191+ <group colspan="4" groups="base.group_extended">
192+ <separator string="Comments" colspan="4"/>
193+ <field colspan="4" name="comments" nolabel="1"/>
194+ </group>
195+ <group>
196+ <separator colspan="4"/>
197+ <newline/>
198+ <button special="cancel" string="Close" icon="gtk-cancel"/>
199+ <button icon="gtk-execute" name="create_xml" string="Create XML" type="object" default_focus="1" />
200+ </group>
201+ </group>
202+ </form>
203+ </field>
204+ </record>
205
206- <record id="view_vat_save" model="ir.ui.view">
207+ <record id="view_vat_save" model="ir.ui.view">
208 <field name="name">Save XML</field>
209 <field name="model">l1on_be.vat.declaration</field>
210 <field name="type">form</field>
211
212=== modified file 'l10n_be/wizard/l10n_be_vat_intra.py' (properties changed: -x to +x)
213--- l10n_be/wizard/l10n_be_vat_intra.py 2012-04-23 16:45:21 +0000
214+++ l10n_be/wizard/l10n_be_vat_intra.py 2012-05-02 07:49:19 +0000
215@@ -55,7 +55,7 @@
216 YYYY stands for the year (4 positions).
217 '''
218 ),
219- 'period_ids': fields.many2many('account.period', 'account_period_rel', 'acc_id', 'period_id', 'Period (s)', help = 'Select here the period(s) you want to include in your intracom declaration'),
220+ 'period_ids': fields.many2many('account.period', 'vat_intra_period_rel', 'acc_id', 'period_id', 'Period (s)', help = 'Select here the period(s) you want to include in your intracom declaration'),
221 'tax_code_id': fields.many2one('account.tax.code', 'Company', domain=[('parent_id', '=', False)], help="Keep empty to use the user's company", required=True),
222 'test_xml': fields.boolean('Test XML file', help="Sets the XML output as test file"),
223 'mand_id' : fields.char('Reference', size=14, help="Reference given by the Representative of the sending company."),
224@@ -95,7 +95,6 @@
225 obj_partner_add = self.pool.get('res.partner.address')
226
227 xmldict = {}
228- post_code = street = city = country = data_clientinfo = ''
229 seq = amount_sum = 0
230
231 wiz_data = self.browse(cr, uid, ids[0], context=context)
232@@ -111,6 +110,7 @@
233 if not company_vat:
234 raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
235 company_vat = company_vat.replace(' ','').upper()
236+ SenderId = company_vat[2:]
237 issued_by = company_vat[:2]
238
239 if len(wiz_data.period_code) != 6:
240@@ -126,24 +126,11 @@
241 seq_declarantnum = obj_sequence.get(cr, uid, 'declarantnum')
242 dnum = company_vat[2:] + seq_declarantnum[-4:]
243
244- addr = obj_partner.address_get(cr, uid, [data_company.partner_id.id], ['invoice'])
245- email = data_company.partner_id.email or ''
246- phone = data_company.partner_id.phone or ''
247-
248- if addr.get('invoice',False):
249- ads = obj_partner_add.browse(cr, uid, [addr['invoice']])[0]
250- city = (ads.city or '')
251- post_code = (ads.zip or '')
252- if ads.street:
253- street = ads.street
254- if ads.street2:
255- street += ' '
256- street += ads.street2
257- if ads.country_id:
258- country = ads.country_id.code
259-
260- if not country:
261- country = company_vat[:2]
262+ name = email = phone = address = post_code = city = country_code = ''
263+ name, email, phone, city, post_code, address, country_code = self.pool.get('res.company')._get_default_ad(data_company.partner_id.address)
264+
265+ if not country_code:
266+ raise osv.except_osv(_('Data Insufficient!'),_('No country associated with the company.'))
267 if not email:
268 raise osv.except_osv(_('Data Insufficient!'),_('No email address associated with the company.'))
269 if not phone:
270@@ -154,10 +141,10 @@
271 'vatnum': company_vat[2:],
272 'mand_id': wiz_data.mand_id,
273 'sender_date': str(time.strftime('%Y-%m-%d')),
274- 'street': street,
275+ 'address': address,
276 'city': city,
277 'post_code': post_code,
278- 'country': country,
279+ 'country_code': country_code,
280 'email': email,
281 'phone': phone.replace('/','').replace('.','').replace('(','').replace(')','').replace(' ',''),
282 'period': wiz_data.period_code,
283@@ -202,12 +189,12 @@
284 'seq': seq,
285 'vatnum': row['vat'][2:].replace(' ','').upper(),
286 'vat': row['vat'],
287- 'country': row['vat'][:2],
288- 'amount': amt,
289+ 'country_code': row['vat'][:2],
290+ 'amount': '%.2f' %amt,
291 'intra_code': row['intra_code'],
292 'code': intra_code})
293
294- xmldict.update({'dnum': dnum, 'clientnbr': str(seq), 'amountsum': amount_sum, 'partner_wo_vat': p_count})
295+ xmldict.update({'dnum': dnum, 'clientnbr': str(seq), 'amountsum': '%.2f' %amount_sum, 'partner_wo_vat': p_count})
296 return xmldict
297
298 def create_xml(self, cursor, user, ids, context=None):
299@@ -225,18 +212,18 @@
300 data_head = """<?xml version="1.0" encoding="ISO-8859-1"?>
301 <ns2:IntraConsignment xmlns="http://www.minfin.fgov.be/InputCommon" xmlns:ns2="http://www.minfin.fgov.be/IntraConsignment" IntraListingsNbr="1">
302 <ns2:Representative>
303- <RepresentativeID identificationType="NVAT" issuedBy="%(issued_by)s">%(company_vat)s</RepresentativeID>
304+ <RepresentativeID identificationType="NVAT" issuedBy="%(issued_by)s">%(vatnum)s</RepresentativeID>
305 <Name>%(company_name)s</Name>
306- <Street>%(street)s</Street>
307+ <Street>%(address)s</Street>
308 <PostCode>%(post_code)s</PostCode>
309 <City>%(city)s</City>
310- <CountryCode>%(country)s</CountryCode>
311+ <CountryCode>%(country_code)s</CountryCode>
312 <EmailAddress>%(email)s</EmailAddress>
313 <Phone>%(phone)s</Phone>
314 </ns2:Representative>""" % (xml_data)
315 if xml_data['mand_id']:
316 data_head += '\n\t\t<ns2:RepresentativeReference>%(mand_id)s</ns2:RepresentativeReference>' % (xml_data)
317- data_comp_period = '\n\t\t<ns2:Declarant>\n\t\t\t<VATNumber>%(vatnum)s</VATNumber>\n\t\t\t<Name>%(company_name)s</Name>\n\t\t\t<Street>%(street)s</Street>\n\t\t\t<PostCode>%(post_code)s</PostCode>\n\t\t\t<City>%(city)s</City>\n\t\t\t<CountryCode>%(country)s</CountryCode>\n\t\t\t<EmailAddress>%(email)s</EmailAddress>\n\t\t\t<Phone>%(phone)s</Phone>\n\t\t</ns2:Declarant>' % (xml_data)
318+ data_comp_period = '\n\t\t<ns2:Declarant>\n\t\t\t<VATNumber>%(vatnum)s</VATNumber>\n\t\t\t<Name>%(company_name)s</Name>\n\t\t\t<Street>%(address)s</Street>\n\t\t\t<PostCode>%(post_code)s</PostCode>\n\t\t\t<City>%(city)s</City>\n\t\t\t<CountryCode>%(country_code)s</CountryCode>\n\t\t\t<EmailAddress>%(email)s</EmailAddress>\n\t\t\t<Phone>%(phone)s</Phone>\n\t\t</ns2:Declarant>' % (xml_data)
319 if month_quarter.startswith('3'):
320 data_comp_period += '\n\t\t<ns2:Period>\n\t\t\t<ns2:Quarter>'+month_quarter[1]+'</ns2:Quarter> \n\t\t\t<ns2:Year>'+year+'</ns2:Year>\n\t\t</ns2:Period>'
321 elif month_quarter.startswith('0') and month_quarter.endswith('0'):
322@@ -248,11 +235,16 @@
323 for client in xml_data['clientlist']:
324 if not client['vatnum']:
325 raise osv.except_osv(_('Data Insufficient!'),_('No vat number defined for %s') % client['partner_name'])
326- data_clientinfo +='\n\t\t<ns2:IntraClient SequenceNumber="%(seq)s">\n\t\t\t<ns2:CompanyVATNumber issuedBy="%(country)s">%(vatnum)s</ns2:CompanyVATNumber>\n\t\t\t<ns2:Code>%(code)s</ns2:Code>\n\t\t\t<ns2:Amount>%(amount)s</ns2:Amount>\n\t\t</ns2:IntraClient>' % (client)
327+ data_clientinfo +='\n\t\t<ns2:IntraClient SequenceNumber="%(seq)s">\n\t\t\t<ns2:CompanyVATNumber issuedBy="%(country_code)s">%(vatnum)s</ns2:CompanyVATNumber>\n\t\t\t<ns2:Code>%(code)s</ns2:Code>\n\t\t\t<ns2:Amount>%(amount)s</ns2:Amount>\n\t\t</ns2:IntraClient>' % (client)
328
329 data_decl = '\n\t<ns2:IntraListing SequenceNumber="1" ClientsNbr="%(clientnbr)s" DeclarantReference="%(dnum)s" AmountSum="%(amountsum)s">' % (xml_data)
330
331- data_file += data_head + data_decl + data_comp_period + data_clientinfo + '\n\t\t<ns2:Comment>%(comments)s</ns2:Comment>\n\t</ns2:IntraListing>\n</ns2:IntraConsignment>' % (xml_data)
332+ data_file += data_head + data_decl + data_comp_period + data_clientinfo
333+ if xml_data['comments']:
334+ data_file += '\n\t\t<ns2:Comment>%(comments)s</ns2:Comment>' % (xml_data)
335+ data_file += '\n\t</ns2:IntraListing>\n</ns2:IntraConsignment>' % (xml_data)
336+
337+
338 context['file_save'] = data_file
339
340 model_data_ids = mod_obj.search(cursor, user,[('model','=','ir.ui.view'),('name','=','view_vat_intra_save')], context=context)
341@@ -291,7 +283,7 @@
342 self.localcontext.update({
343 'time': time,
344 })
345-
346+
347 report_sxw.report_sxw('report.partner.vat.intra.print', 'partner.vat.intra', 'addons/l10n_be/wizard/l10n_be_vat_intra_print.rml', parser=vat_intra_print, header="internal")
348
349 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: