Merge lp:~zikzak/magentoerpconnect/check_vat into lp:magentoerpconnect/oerp6.0-stable

Proposed by Raimon Esteve (www.zikzakmedia.com)
Status: Needs review
Proposed branch: lp:~zikzak/magentoerpconnect/check_vat
Merge into: lp:magentoerpconnect/oerp6.0-stable
Diff against target: 70 lines (+27/-8)
2 files modified
sale.py (+23/-6)
sale_view.xml (+4/-2)
To merge this branch: bzr merge lp:~zikzak/magentoerpconnect/check_vat
Reviewer Review Type Date Requested Status
MagentoERPConnect core editors Pending
Review via email: mp+51102@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Guys, I'm not sure if we should merge this or not. Is that code generic enough?
Here in Brazil for instance we made a new extension module to deal with VAT and other legal stuff:
https://code.launchpad.net/~akretion-team/magentoerpconnect/magentoerpconnect_br
Others could give their views please?

Revision history for this message
Raimon Esteve (www.zikzakmedia.com) (resteve) wrote :

Now, there are bug if recibe partner with VAT and of course, don't
create partner, not create sale ;)

You can configure in sale.order what vat would do chek and use def
openerp check_vat, for exampe, check_vat_es.

--
Raimon Esteve
// OpenERP Partner. www.openerp.com/node/682
// e-sale: Zoook 100% OpenERP / Magento
// AulaERP, formació online www.aulaerp.com
www.zikzakmedia.com

Unmerged revisions

392. By Raimon Esteve (www.zikzakmedia.com)

[IMP] Add revision 391 and Check VAT features

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sale.py'
2--- sale.py 2011-01-19 02:57:13 +0000
3+++ sale.py 2011-02-24 10:57:58 +0000
4@@ -120,6 +120,7 @@
5 'auto_import': fields.boolean('Automatic Import'),
6 'allow_magento_order_status_push': fields.boolean('Allow Magento Order Status push', help='Allow to send back order status to Magento if order status changed in OpenERP first?'),
7 'allow_magento_notification': fields.boolean('Allow Magento Notification', help='Allow Magento to notify customer (mail) if OpenERP update Magento order status?'),
8+ 'vat_country_ids': fields.many2many('res.country','sale_shop_vat_country_rel', 'shop_id','country_id','Vat Country'),
9 }
10
11 _defaults = {
12@@ -346,19 +347,35 @@
13 # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat
14 cr.execute('select * from ir_module_module where name=%s and state=%s', ('base_vat','installed'))
15 if cr.fetchone() and 'customer_taxvat' in data_record and data_record['customer_taxvat']:
16+ check_vat = True
17 allchars = string.maketrans('', '')
18 delchars = ''.join([c for c in allchars if c not in string.letters + string.digits])
19 vat = data_record['customer_taxvat'].translate(allchars, delchars).upper()
20- vat_country, vat_number = vat[:2].lower(), vat[2:]
21- check = getattr(partner_obj, 'check_vat_' + vat_country)
22- vat_ok = check(vat_number)
23- if not vat_ok and 'country_id' in data_record['billing_address']:
24+ vat_country = vat[:2]
25+
26+ if not hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
27+ shop = self.pool.get('sale.shop').browse(cr, uid, res['shop_id'])
28+ for country_id in shop.vat_country_ids:
29+ vat_country = country_id.code
30+ if hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
31+ check_vat = True
32+ break
33+
34+ if check_vat and hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
35+ check = getattr(partner_obj, 'check_vat_' + vat_country.lower())
36+ vat_ok = check(vat)
37+ else:
38+ vat_ok = False
39+
40+ if not vat_ok and 'country_id' in data_record['billing_address'] and hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
41 # Maybe magento vat number has not country code prefix. Take it from billing address.
42 check = getattr(partner_obj, 'check_vat_' + data_record['billing_address']['country_id'].lower())
43 vat_ok = check(vat)
44 vat = data_record['billing_address']['country_id'] + vat
45- if vat_ok:
46- partner_obj.write(cr, uid, [partner_id], {'vat_subjected':True, 'vat':vat})
47+
48+ if vat_ok:
49+ partner_obj.write(cr, uid, [partner_id], {'vat_subjected':True, 'vat':(vat_country+vat).upper()})
50+
51 return res
52
53 def get_order_lines(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context):
54
55=== modified file 'sale_view.xml'
56--- sale_view.xml 2011-01-18 17:37:25 +0000
57+++ sale_view.xml 2011-02-24 10:57:58 +0000
58@@ -61,8 +61,10 @@
59 <page string="Magento Information">
60 <field name="magento_shop" />
61 <field name="auto_import" />
62- <field name="allow_magento_order_status_push" />
63- <field name="allow_magento_notification" attrs="{'invisible':[('allow_magento_order_status_push','=',False)]}"/>
64+ <field name="allow_magento_order_status_push" />
65+ <field name="allow_magento_notification" attrs="{'invisible':[('allow_magento_order_status_push','=',False)]}"/>
66+ <separator string="Allow countries check Vat" colspan="4" />
67+ <field name="vat_country_ids" nolabel="1" colspan="4"/>
68 </page>
69 </xpath>
70 </field>