Merge lp:~qdp/openobject-addons/5.0-l10nbe-intervat5.1.0-compliancy into lp:openobject-addons/5.0

Proposed by qdp (OpenERP)
Status: Merged
Merged at revision: not available
Proposed branch: lp:~qdp/openobject-addons/5.0-l10nbe-intervat5.1.0-compliancy
Merge into: lp:openobject-addons/5.0
Diff against target: 434 lines (+110/-147)
5 files modified
account/account_bank_statement.py (+26/-21)
l10n_be/account_pcmn_belgium.xml (+29/-7)
l10n_be/company.py (+4/-2)
l10n_be/wizard/account_vat_declaration.py (+14/-12)
l10n_be/wizard/wizard_vat_intra.py (+37/-105)
To merge this branch: bzr merge lp:~qdp/openobject-addons/5.0-l10nbe-intervat5.1.0-compliancy
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+22893@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
=== modified file 'account/account_bank_statement.py'
--- account/account_bank_statement.py 2010-02-04 11:47:04 +0000
+++ account/account_bank_statement.py 2010-04-06 17:52:20 +0000
@@ -529,35 +529,40 @@
529529
530 def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,530 def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,
531 context={}):531 context={}):
532 res = {'value': {}}
532 if not partner_id:533 if not partner_id:
533 return {}534 return res
534 res_currency_obj = self.pool.get('res.currency')535 line = self.browse(cursor, user, line_id)
535 res_users_obj = self.pool.get('res.users')536
536537 if not line or (line and not line[0].account_id):
537 company_currency_id = res_users_obj.browse(cursor, user, user,538 part = self.pool.get('res.partner').browse(cursor, user, partner_id,
538 context=context).company_id.currency_id.id
539
540 if not currency_id:
541 currency_id = company_currency_id
542
543 part = self.pool.get('res.partner').browse(cursor, user, partner_id,
544 context=context)539 context=context)
545 if type == 'supplier':540 if type == 'supplier':
546 account_id = part.property_account_payable.id541 account_id = part.property_account_payable.id
547 else:542 else:
548 account_id = part.property_account_receivable.id543 account_id = part.property_account_receivable.id
549544 res['value']['account_id'] = account_id
550 cursor.execute('SELECT sum(debit-credit) \545
546 if not line or (line and not line[0].amount):
547 res_users_obj = self.pool.get('res.users')
548 res_currency_obj = self.pool.get('res.currency')
549 company_currency_id = res_users_obj.browse(cursor, user, user,
550 context=context).company_id.currency_id.id
551 if not currency_id:
552 currency_id = company_currency_id
553
554 cursor.execute('SELECT sum(debit-credit) \
551 FROM account_move_line \555 FROM account_move_line \
552 WHERE (reconcile_id is null) \556 WHERE (reconcile_id is null) \
553 AND partner_id = %s \557 AND partner_id = %s \
554 AND account_id=%s', (partner_id, account_id))558 AND account_id=%s', (partner_id, account_id))
555 res = cursor.fetchone()559 pgres = cursor.fetchone()
556 balance = res and res[0] or 0.0560 balance = pgres and pgres[0] or 0.0
557561
558 balance = res_currency_obj.compute(cursor, user, company_currency_id,562 balance = res_currency_obj.compute(cursor, user, company_currency_id,
559 currency_id, balance, context=context)563 currency_id, balance, context=context)
560 return {'value': {'amount': balance, 'account_id': account_id}}564 res['value']['amount'] = balance
565 return res
561566
562 def _reconcile_amount(self, cursor, user, ids, name, args, context=None):567 def _reconcile_amount(self, cursor, user, ids, name, args, context=None):
563 if not ids:568 if not ids:
564569
=== modified file 'l10n_be/account_pcmn_belgium.xml'
--- l10n_be/account_pcmn_belgium.xml 2010-03-08 13:26:39 +0000
+++ l10n_be/account_pcmn_belgium.xml 2010-04-06 17:52:20 +0000
@@ -6466,9 +6466,20 @@
6466 </record>6466 </record>
6467 <record id="vat_code_a44" model="account.tax.code.template">6467 <record id="vat_code_a44" model="account.tax.code.template">
6468 <field name="code">44</field>6468 <field name="code">44</field>
6469 <field name="name">Services intra-communautaires et ABC</field>
6470 <field name="parent_id" ref="vat_code_out"/>
6471 </record>
6472 <record id="vat_code_a44a" model="account.tax.code.template">
6473 <field name="code">44a</field>
6469 <field name="name">Services intra-communautaires</field>6474 <field name="name">Services intra-communautaires</field>
6470 <field name="parent_id" ref="vat_code_out"/>6475 <field name="parent_id" ref="vat_code_a44"/>
6471 </record>6476 </record>
6477 <record id="vat_code_a44b" model="account.tax.code.template">
6478 <field name="code">44b</field>
6479 <field name="name">ABC intra-communautaires</field>
6480 <field name="parent_id" ref="vat_code_a44"/>
6481 </record>
6482
6472 <record id="vat_code_a45" model="account.tax.code.template">6483 <record id="vat_code_a45" model="account.tax.code.template">
6473 <field name="code">45</field>6484 <field name="code">45</field>
6474 <field name="name">Operations avec TVA due par le cocontractant</field>6485 <field name="name">Operations avec TVA due par le cocontractant</field>
@@ -7053,14 +7064,25 @@
7053 </record>7064 </record>
7054 <record id="vat_IO_S" model="account.tax.template">7065 <record id="vat_IO_S" model="account.tax.template">
7055 <field name="chart_template_id" ref="l10nbe_chart_template"/>7066 <field name="chart_template_id" ref="l10nbe_chart_template"/>
7056 <field name="name">TVA 0% Intracommunautaire (Services et ABC)</field>7067 <field name="name">TVA 0% Services Intracommunautaires</field>
7057 <field name="description">V-INTRA-S 0</field>7068 <field name="description">V-INTRA-S 0</field>
7058 <field eval="0.00" name="amount"/>7069 <field eval="0.00" name="amount"/>
7059 <field name="type">percent</field>7070 <field name="type">percent</field>
7060 <field name="base_code_id" ref="vat_code_a44"/>7071 <field name="base_code_id" ref="vat_code_a44a"/>
7061 <field name="ref_base_code_id" ref="vat_code_a48"/>7072 <field name="ref_base_code_id" ref="vat_code_a48"/>
7062 <field name="type_tax_use">sale</field>7073 <field name="type_tax_use">sale</field>
7063 </record>7074 </record>
7075 <record id="vat_IO_S" model="account.tax.template">
7076 <field name="chart_template_id" ref="l10nbe_chart_template"/>
7077 <field name="name">TVA 0% ABC Intracommunautaire</field>
7078 <field name="description">V-INTRA-ABC 0</field>
7079 <field eval="0.00" name="amount"/>
7080 <field name="type">percent</field>
7081 <field name="base_code_id" ref="vat_code_a44b"/>
7082 <field name="ref_base_code_id" ref="vat_code_a48"/>
7083 <field name="type_tax_use">sale</field>
7084 </record>
7085
70647086
7065 <!-- Purchases VAT -->7087 <!-- Purchases VAT -->
7066 <record id="vat_IO_buy_21b" model="account.tax.template">7088 <record id="vat_IO_buy_21b" model="account.tax.template">
70677089
=== modified file 'l10n_be/company.py'
--- l10n_be/company.py 2009-02-05 05:43:13 +0000
+++ l10n_be/company.py 2010-04-06 17:52:20 +0000
@@ -28,7 +28,7 @@
2828
2929
30 def _get_default_ad(self, addresses):30 def _get_default_ad(self, addresses):
31 city = post_code = address = ""31 city = post_code = address = country_code = ""
32 for ads in addresses:32 for ads in addresses:
33 if ads.type == 'default':33 if ads.type == 'default':
34 city = ads.city or ""34 city = ads.city or ""
@@ -37,7 +37,9 @@
37 address = ads.street or ""37 address = ads.street or ""
38 if ads.street2:38 if ads.street2:
39 address += " " + ads.street239 address += " " + ads.street2
40 return city, post_code, address40 if ads.country_id:
41 country_code = ads.country_id and ads.country_id.code or ""
42 return city, post_code, address, country_code
41res_company()43res_company()
4244
43# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:45# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
4446
=== modified file 'l10n_be/wizard/account_vat_declaration.py'
--- l10n_be/wizard/account_vat_declaration.py 2009-04-09 10:02:19 +0000
+++ l10n_be/wizard/account_vat_declaration.py 2010-04-06 17:52:20 +0000
@@ -30,10 +30,16 @@
30form_fyear = """<?xml version="1.0"?>30form_fyear = """<?xml version="1.0"?>
31<form string="Select Period">31<form string="Select Period">
32 <field name="period" />32 <field name="period" />
33 <field name="ask_resitution"/>
34 <field name="ask_payment"/>
35 <field name="client_nihil"/>
33</form>"""36</form>"""
3437
35fields_fyear = {38fields_fyear = {
36 'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period', 'required': True,},39 'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period', 'required': True,},
40 'ask_resitution': {'type': 'boolean', 'string': 'Ask Restitution',},
41 'ask_payment': {'type': 'boolean', 'string': 'Ask Payment',},
42 'client_nihil': {'type': 'boolean', 'string': 'Last Declaration of Entreprise', 'help': 'Thick this case only if it concerns only the last statement on the civil or cessation of activity'},
37}43}
3844
39form = """<?xml version="1.0"?>45form = """<?xml version="1.0"?>
@@ -54,7 +60,7 @@
54class wizard_vat_declaration(wizard.interface):60class wizard_vat_declaration(wizard.interface):
5561
56 def _create_xml(self, cr, uid, data, context):62 def _create_xml(self, cr, uid, data, context):
57 list_of_tags=['00','01','02','03','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','81','82','83','84','85','86','87','91']63 list_of_tags=['00','01','02','03','44','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','81','82','83','84','85','86','87','88','91']
58 pool_obj = pooler.get_pool(cr.dbname)64 pool_obj = pooler.get_pool(cr.dbname)
59 #obj_company = pool_obj.get('res.company').browse(cr,uid,1)65 #obj_company = pool_obj.get('res.company').browse(cr,uid,1)
60 obj_company = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id66 obj_company = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id
@@ -68,27 +74,22 @@
68 ctx['period_id'] = data['form']['period'] #added context here74 ctx['period_id'] = data['form']['period'] #added context here
69 tax_info = pool_obj.get('account.tax.code').read(cr,uid,tax_ids,['code','sum_period'],context=ctx)75 tax_info = pool_obj.get('account.tax.code').read(cr,uid,tax_ids,['code','sum_period'],context=ctx)
7076
71 address=post_code=city=''77 address = post_code = city = country_code = ''
72 if not obj_company.partner_id.address:
73 address=post_code=city=''
7478
75 city, post_code, address = pooler.get_pool(cr.dbname).get('res.company')._get_default_ad(obj_company.partner_id.address)79 city, post_code, address, country_code = pooler.get_pool(cr.dbname).get('res.company')._get_default_ad(obj_company.partner_id.address)
7680
77 obj_fyear = pool_obj.get('account.fiscalyear')81 obj_fyear = pool_obj.get('account.fiscalyear')
78 year_id = obj_fyear.find(cr, uid)82 year_id = obj_fyear.find(cr, uid)
79 83
80 account_period=pool_obj.get('account.period').browse(cr, uid, data['form']['period'])84 account_period=pool_obj.get('account.period').browse(cr, uid, data['form']['period'])
81 current_year = account_period.fiscalyear_id.name
82 period_code = account_period.code85 period_code = account_period.code
8386
84 send_ref = user_cmpny87 send_ref = str(obj_company.partner_id.id) + str(account_period.date_start[5:7]) + str(account_period.date_stop[:4])
85 if period_code:
86 send_ref = send_ref + period_code
8788
88 data_of_file='<?xml version="1.0"?>\n<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MultiDeclarationTVA-NoSignature-14.xml">'89 data_of_file='<?xml version="1.0"?>\n<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MultiDeclarationTVA-NoSignature-14.xml">'
89 data_of_file +='\n\t<DECLARER>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<NAME>'+str(obj_company.name)+'</NAME>\n\t\t<ADDRESS>'+address+'</ADDRESS>'90 data_of_file +='\n\t<DECLARER>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<NAME>'+str(obj_company.name)+'</NAME>\n\t\t<ADDRESS>'+address+'</ADDRESS>'
90 data_of_file +='\n\t\t<POSTCODE>'+post_code+'</POSTCODE>\n\t\t<CITY>'+city+'</CITY>\n\t\t<SENDINGREFERENCE>'+send_ref+'</SENDINGREFERENCE>\n\t</DECLARER>'91 data_of_file +='\n\t\t<POSTCODE>'+post_code+'</POSTCODE>\n\t\t<CITY>'+city+'</CITY>\n\t\t<COUNTRY>'+country_code+'</COUNTRY>\n\t\t<SENDINGREFERENCE>'+send_ref+'</SENDINGREFERENCE>\n\t</DECLARER>'
91 data_of_file +='\n\t<VATRECORD>\n\t\t<RECNUM>1</RECNUM>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<DPERIODE>\n\t\t\t'92 data_of_file +='\n\t<VATRECORD>\n\t\t<RECNUM>1</RECNUM>\n\t\t<VATNUMBER>'+str(vat_no[2:])+'</VATNUMBER>\n\t\t<DPERIODE>\n\t\t\t'
9293
93 starting_month = account_period.date_start[5:7]94 starting_month = account_period.date_start[5:7]
94 ending_month = account_period.date_stop[5:7]95 ending_month = account_period.date_stop[5:7]
@@ -100,6 +101,7 @@
100 else:101 else:
101 data_of_file += '<MONTH>'+starting_month+'</MONTH>\n\t\t\t'102 data_of_file += '<MONTH>'+starting_month+'</MONTH>\n\t\t\t'
102 data_of_file += '<YEAR>' + str(account_period.date_stop[:4]) + '</YEAR>\n\t\t</DPERIODE>\n\t\t<ASK RESTITUTION="NO" PAYMENT="NO"/>'103 data_of_file += '<YEAR>' + str(account_period.date_stop[:4]) + '</YEAR>\n\t\t</DPERIODE>\n\t\t<ASK RESTITUTION="NO" PAYMENT="NO"/>'
104 data_of_file += '\n\t\t<ClientListingNihil>'+ (data['form']['client_nihil'] and 'YES' or 'NO') +'</ClientListingNihil>'
103 data_of_file +='\n\t\t<DATA>\n\t\t\t<DATA_ELEM>'105 data_of_file +='\n\t\t<DATA>\n\t\t\t<DATA_ELEM>'
104106
105 for item in tax_info:107 for item in tax_info:
@@ -107,7 +109,7 @@
107 if item['code'] == '71-72':109 if item['code'] == '71-72':
108 item['code']='71'110 item['code']='71'
109 if item['code'] in list_of_tags:111 if item['code'] in list_of_tags:
110 data_of_file +='\n\t\t\t\t<D'+str(int(item['code'])) +'>' + str(int(item['sum_period']*100)) + '</D'+str(int(item['code'])) +'>'112 data_of_file +='\n\t\t\t\t<D'+str(int(item['code'])) +'>' + str(abs(int(item['sum_period']*100))) + '</D'+str(int(item['code'])) +'>'
111113
112 data_of_file +='\n\t\t\t</DATA_ELEM>\n\t\t</DATA>\n\t</VATRECORD>\n</VATSENDING>'114 data_of_file +='\n\t\t\t</DATA_ELEM>\n\t\t</DATA>\n\t</VATRECORD>\n</VATSENDING>'
113 data['form']['msg']='Save the File with '".xml"' extension.'115 data['form']['msg']='Save the File with '".xml"' extension.'
114116
=== modified file 'l10n_be/wizard/wizard_vat_intra.py'
--- l10n_be/wizard/wizard_vat_intra.py 2009-03-24 11:01:43 +0000
+++ l10n_be/wizard/wizard_vat_intra.py 2010-04-06 17:52:20 +0000
@@ -30,6 +30,7 @@
30import datetime30import datetime
31import pooler31import pooler
32import base6432import base64
33from tools.translate import _
3334
34form_intra = """<?xml version="1.0"?>35form_intra = """<?xml version="1.0"?>
35<form string="Partner VAT Intra">36<form string="Partner VAT Intra">
@@ -37,13 +38,12 @@
37 <page string="General Information">38 <page string="General Information">
38 <label string="This wizard will create an XML file for Vat Intra" colspan="4"/>39 <label string="This wizard will create an XML file for Vat Intra" colspan="4"/>
39 <newline/>40 <newline/>
40 <field name="fyear" />41 <field name="period_code"/>
42 <newline/>
43 <field name="period_ids"/>
41 <newline/>44 <newline/>
42 <field name="mand_id" help="This identifies the representative of the sending company. This is a string of 14 characters"/>45 <field name="mand_id" help="This identifies the representative of the sending company. This is a string of 14 characters"/>
43 <newline/>46 <newline/>
44 <field name="trimester" help="it will be the first digit of period" />
45 <newline/>
46 <field name="test_xml" help="Set the XML output as test file"/>
47 </page>47 </page>
48 <page string="European Countries">48 <page string="European Countries">
49 <field name="country_ids" colspan="4" nolabel="1" />49 <field name="country_ids" colspan="4" nolabel="1" />
@@ -51,14 +51,18 @@
51 </notebook>51 </notebook>
52</form>"""52</form>"""
53fields_intra = {53fields_intra = {
54 'trimester': {'string': 'Trimester Number', 'type': 'selection', 'selection':[54 'period_code': {'string':'Period Code','type':'char','size':'6','required': True, 'help': '''This is where you have to set the period code for the intracom declaration using the format: ppyyyy
55 ('1','Jan/Feb/Mar'),55
56 ('2','Apr/May/Jun'),56 PP can stand for a month: from '01' to '12'.
57 ('3','Jul/Aug/Sep'),57 PP can stand for a trimester: '31','32','33','34'
58 ('4','Oct/Nov/Dec')], 'required': True},58 The first figure means that it is a trimester,
59 'test_xml': {'string':'Test XML file', 'type':'boolean'},59 The second figure identify the trimester.
60 PP can stand for a complete fiscal year: '00'.
61 YYYY stands for the year (4 positions).
62'''
63},
64 'period_ids': {'string': 'Period(s)', 'type': 'many2many', 'relation': 'account.period', 'required': True, 'help': 'Select here the period(s) you want to include in your intracom declaration'},
60 'mand_id':{'string':'MandataireId','type':'char','size':'14','required': True},65 'mand_id':{'string':'MandataireId','type':'char','size':'14','required': True},
61 'fyear': {'string': 'Fiscal Year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
62 'country_ids': {66 'country_ids': {
63 'string': 'European Countries',67 'string': 'European Countries',
64 'type': 'many2many',68 'type': 'many2many',
@@ -89,19 +93,16 @@
89 def _create_xml(self, cr, uid, data, context):93 def _create_xml(self, cr, uid, data, context):
90 pool = pooler.get_pool(cr.dbname)94 pool = pooler.get_pool(cr.dbname)
91 data_cmpny = pool.get('res.users').browse(cr, uid, uid).company_id95 data_cmpny = pool.get('res.users').browse(cr, uid, uid).company_id
92 data_fiscal = pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear'])
93 company_vat = data_cmpny.partner_id.vat96 company_vat = data_cmpny.partner_id.vat
94
95 if not company_vat:97 if not company_vat:
96 raise wizard.except_wizard('Data Insufficient','No VAT Number Associated with Main Company!')98 raise wizard.except_wizard('Data Insufficient','No VAT Number Associated with Main Company!')
9799
98 seq_controlref = pool.get('ir.sequence').get(cr, uid,'controlref')100 seq_controlref = pool.get('ir.sequence').get(cr, uid,'controlref')
99 seq_declarantnum = pool.get('ir.sequence').get(cr, uid,'declarantnum')101 seq_declarantnum = pool.get('ir.sequence').get(cr, uid,'declarantnum')
100 cref = company_vat + seq_controlref102 cref = company_vat[2:] + seq_controlref[-4:]
101 dnum = cref + seq_declarantnum103 dnum = cref + seq_declarantnum[-5:]
102 if len(data_fiscal.date_start.split('-')[0]) < 4:104 if len(data['form']['period_code']) != 6:
103 raise wizard.except_wizard('Data Insufficient','Trimester year should be length of 4 digits!')105 raise wizard.except_wizard(_('Wrong Period Code'), _('The period code you entered is not valid.'))
104 period_trimester = data['form']['trimester'] + data_fiscal.date_start.split('-')[0]
105106
106 street = zip_city = country = ''107 street = zip_city = country = ''
107 addr = pool.get('res.partner').address_get(cr, uid, [data_cmpny.partner_id.id], ['invoice'])108 addr = pool.get('res.partner').address_get(cr, uid, [data_cmpny.partner_id.id], ['invoice'])
@@ -121,103 +122,34 @@
121 sender_date = time.strftime('%Y-%m-%d')122 sender_date = time.strftime('%Y-%m-%d')
122 data_file = '<?xml version="1.0"?>\n<VatIntra xmlns="http://www.minfin.fgov.be/VatIntra" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RecipientId="VAT-ADMIN" SenderId="' + str(company_vat) + '"'123 data_file = '<?xml version="1.0"?>\n<VatIntra xmlns="http://www.minfin.fgov.be/VatIntra" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RecipientId="VAT-ADMIN" SenderId="' + str(company_vat) + '"'
123 data_file +=' ControlRef="' + cref + '" MandataireId="' + data['form']['mand_id'] + '" SenderDate="'+ str(sender_date)+ '"'124 data_file +=' ControlRef="' + cref + '" MandataireId="' + data['form']['mand_id'] + '" SenderDate="'+ str(sender_date)+ '"'
124 if data['form']['test_xml']:125 data_file += ' VersionTech="1.3">'
125 data_file += ' Test="1"'
126 data_file += ' VersionTech="1.2">'
127 data_file +='\n\t<AgentRepr DecNumber="1">\n\t\t<CompanyInfo>\n\t\t\t<VATNum>' + str(company_vat)+'</VATNum>\n\t\t\t<Name>'+str(data_cmpny.name)+'</Name>\n\t\t\t<Street>'+ str(street) +'</Street>\n\t\t\t<CityAndZipCode>'+ str(zip_city) +'</CityAndZipCode>'126 data_file +='\n\t<AgentRepr DecNumber="1">\n\t\t<CompanyInfo>\n\t\t\t<VATNum>' + str(company_vat)+'</VATNum>\n\t\t\t<Name>'+str(data_cmpny.name)+'</Name>\n\t\t\t<Street>'+ str(street) +'</Street>\n\t\t\t<CityAndZipCode>'+ str(zip_city) +'</CityAndZipCode>'
128 data_file +='\n\t\t\t<Country>' + str(country) +'</Country>\n\t\t</CompanyInfo>\n\t</AgentRepr>'127 data_file +='\n\t\t\t<Country>' + str(country) +'</Country>\n\t\t</CompanyInfo>\n\t</AgentRepr>'
129128
130 data_comp ='\n\t\t<CompanyInfo>\n\t\t\t<VATNum>'+str(company_vat)+'</VATNum>\n\t\t\t<Name>'+str(data_cmpny.name)+'</Name>\n\t\t\t<Street>'+ str(street) +'</Street>\n\t\t\t<CityAndZipCode>'+ str(zip_city) +'</CityAndZipCode>\n\t\t\t<Country>'+ str(country) +'</Country>\n\t\t</CompanyInfo>'129 data_comp ='\n\t\t<CompanyInfo>\n\t\t\t<VATNum>'+str(company_vat[2:])+'</VATNum>\n\t\t\t<Name>'+str(data_cmpny.name)+'</Name>\n\t\t\t<Street>'+ str(street) +'</Street>\n\t\t\t<CityAndZipCode>'+ str(zip_city) +'</CityAndZipCode>\n\t\t\t<Country>'+ str(country) +'</Country>\n\t\t</CompanyInfo>'
131 data_period = '\n\t\t<Period>'+ str(period_trimester) +'</Period>' #trimester130 data_period = '\n\t\t<Period>'+ data['form']['period_code'] +'</Period>' #trimester
132131
133 error_message = []132 error_message = []
134 seq = 0133 seq = 0
135 amount_sum = 0134 amount_sum = 0
136 p_id_list = pool.get('res.partner').search(cr,uid,[('vat','!=',False)])135
137 if not p_id_list:136 list_partner = []
138 raise wizard.except_wizard('Data Insufficient!','No partner has a VAT Number asociated with him.')
139
140 nb_period = len(data_fiscal.period_ids)
141 fiscal_periods = data_fiscal.period_ids
142
143 if data['form']['trimester'] == '1':
144 if nb_period == 12:
145 start_date = fiscal_periods[0].date_start
146 end_date = fiscal_periods[2].date_stop
147 elif nb_period == 4:
148 start_date = fiscal_periods[0].date_start
149 end_date = fiscal_periods[0].date_stop
150 elif data['form']['trimester'] == '2':
151 if nb_period == 12:
152 start_date = fiscal_periods[3].date_start
153 end_date = fiscal_periods[5].date_stop
154 elif nb_period == 4:
155 start_date = fiscal_periods[1].date_start
156 end_date = fiscal_periods[1].date_stop
157 elif data['form']['trimester'] == '3':
158 if nb_period == 12:
159 start_date = fiscal_periods[6].date_start
160 end_date = fiscal_periods[8].date_stop
161 elif nb_period == 4:
162 start_date = fiscal_periods[2].date_start
163 end_date = fiscal_periods[2].date_stop
164 elif data['form']['trimester'] == '4':
165 if nb_period == 12:
166 start_date = fiscal_periods[9].date_start
167 end_date = fiscal_periods[11].date_stop
168 elif nb_period == 4:
169 start_date = fiscal_periods[3].date_start
170 end_date = fiscal_periods[3].date_stop
171
172 period = "to_date('" + str(start_date) + "','yyyy-mm-dd') and to_date('" + str(end_date) +"','yyyy-mm-dd')"
173 record = {}
174
175 for p_id in p_id_list:
176 list_partner = []
177 partner = pool.get('res.partner').browse(cr, uid, p_id)
178 go_ahead = False
179 country_code = ''
180 for ads in partner.address:
181 if ads.type == 'default' and (ads.country_id and ads.country_id.id in data['form']['country_ids'][0][2]):
182 go_ahead = True
183 country_code = ads.country_id.code
184 break
185 if not go_ahead:
186 continue
187
188 cr.execute('select sum(debit)-sum(credit) as amount from account_move_line l left join account_account a on (l.account_id=a.id) where a.type in ('"'receivable'"') and l.partner_id=%%s and l.date between %s' % (period,), (p_id,))
189 res = cr.dictfetchall()
190 list_partner.append(res[0]['amount'])
191 list_partner.append('T') #partner.ref ...should be check
192 list_partner.append(partner.vat)
193 list_partner.append(country_code)
194 #...deprecated...
195# addr = pool.get('res.partner').address_get(cr, uid, [partner.id], ['invoice'])
196# if addr.get('invoice',False):
197# ads = pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
198#
199# if ads.country_id:
200# code_country = ads.country_id.code
201# list_partner.append(code_country)
202# else:
203# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no country associated with its Invoice address!')
204# if len(list_partner)<4:
205# list_partner.append('')
206# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no Invoice address!')
207# list_partner.append(code_country or 'not avail')
208 record[p_id] = list_partner
209
210 if len(error_message):
211 data['form']['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
212 return data['form']
213 data_clientinfo = ''137 data_clientinfo = ''
214138 cr.execute('''SELECT l.partner_id AS partner_id, p.vat AS vat, t.code AS intra_code, SUM(l.tax_amount) AS amount
215 for r in record:139 FROM account_move_line l
140 LEFT JOIN account_tax_code t ON (l.tax_code_id = t.id)
141 LEFT JOIN res_partner p ON (l.partner_id = p.id)
142 WHERE t.code IN ('44a','44b','88')
143 AND l.period_id IN %s
144 GROUP BY l.partner_id, p.vat, t.code''', (tuple(data['form']['period_ids'][0][2]), ))
145 for row in cr.dictfetchall():
216 seq += 1146 seq += 1
217 amt = record[r][0] or 0147 amt = row['amount'] or 0
218 amt = int(amt * 100)148 amt = int(amt * 100)
219 amount_sum += amt149 amount_sum += amt
220 data_clientinfo +='\n\t\t<ClientList SequenceNum="'+str(seq)+'">\n\t\t\t<CompanyInfo>\n\t\t\t\t<VATNum>'+record[r][2] +'</VATNum>\n\t\t\t\t<Country>'+record[r][3] +'</Country>\n\t\t\t</CompanyInfo>\n\t\t\t<Amount>'+str(amt) +'</Amount>\n\t\t\t<Period>'+str(period_trimester) +'</Period>\n\t\t\t<Code>'+str(record[r][1]) +'</Code>\n\t\t</ClientList>'150 intra_code = row['intra_code'] == '88' and 'L' or (row['intra_code'] == '44b' and 'T' or (row['intra_code'] == '44a' and 'S' or ''))
151 data_clientinfo +='\n\t\t<ClientList SequenceNum="'+str(seq)+'">\n\t\t\t<CompanyInfo>\n\t\t\t\t<VATNum>'+row['vat'][2:] +'</VATNum>\n\t\t\t\t<Country>'+row['vat'][:2] +'</Country>\n\t\t\t</CompanyInfo>\n\t\t\t<Amount>'+str(amt) +'</Amount>\n\t\t\t<Code>'+str(intra_code) +'</Code>\n\t\t</ClientList>'
152
221 amount_sum = int(amount_sum)153 amount_sum = int(amount_sum)
222 data_decl = '\n\t<DeclarantList SequenceNum="1" DeclarantNum="'+ dnum + '" ClientNbr="'+ str(seq) +'" AmountSum="'+ str(amount_sum) +'" >'154 data_decl = '\n\t<DeclarantList SequenceNum="1" DeclarantNum="'+ dnum + '" ClientNbr="'+ str(seq) +'" AmountSum="'+ str(amount_sum) +'" >'
223 data_file += str(data_decl) + str(data_comp) + str(data_period) + str(data_clientinfo) + '\n\t</DeclarantList>\n</VatIntra>'155 data_file += str(data_decl) + str(data_comp) + str(data_period) + str(data_clientinfo) + '\n\t</DeclarantList>\n</VatIntra>'
@@ -235,4 +167,4 @@
235 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},167 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},
236 }168 }
237 }169 }
238parter_vat_intra('vat.intra.xml')
239\ No newline at end of file170\ No newline at end of file
171parter_vat_intra('vat.intra.xml')