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
=== modified file 'sale.py'
--- sale.py 2011-01-19 02:57:13 +0000
+++ sale.py 2011-02-24 10:57:58 +0000
@@ -120,6 +120,7 @@
120 'auto_import': fields.boolean('Automatic Import'),120 'auto_import': fields.boolean('Automatic Import'),
121 '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?'),121 '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?'),
122 'allow_magento_notification': fields.boolean('Allow Magento Notification', help='Allow Magento to notify customer (mail) if OpenERP update Magento order status?'),122 'allow_magento_notification': fields.boolean('Allow Magento Notification', help='Allow Magento to notify customer (mail) if OpenERP update Magento order status?'),
123 'vat_country_ids': fields.many2many('res.country','sale_shop_vat_country_rel', 'shop_id','country_id','Vat Country'),
123 } 124 }
124125
125 _defaults = {126 _defaults = {
@@ -346,19 +347,35 @@
346 # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat347 # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat
347 cr.execute('select * from ir_module_module where name=%s and state=%s', ('base_vat','installed'))348 cr.execute('select * from ir_module_module where name=%s and state=%s', ('base_vat','installed'))
348 if cr.fetchone() and 'customer_taxvat' in data_record and data_record['customer_taxvat']:349 if cr.fetchone() and 'customer_taxvat' in data_record and data_record['customer_taxvat']:
350 check_vat = True
349 allchars = string.maketrans('', '')351 allchars = string.maketrans('', '')
350 delchars = ''.join([c for c in allchars if c not in string.letters + string.digits])352 delchars = ''.join([c for c in allchars if c not in string.letters + string.digits])
351 vat = data_record['customer_taxvat'].translate(allchars, delchars).upper()353 vat = data_record['customer_taxvat'].translate(allchars, delchars).upper()
352 vat_country, vat_number = vat[:2].lower(), vat[2:]354 vat_country = vat[:2]
353 check = getattr(partner_obj, 'check_vat_' + vat_country)355
354 vat_ok = check(vat_number)356 if not hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
355 if not vat_ok and 'country_id' in data_record['billing_address']:357 shop = self.pool.get('sale.shop').browse(cr, uid, res['shop_id'])
358 for country_id in shop.vat_country_ids:
359 vat_country = country_id.code
360 if hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
361 check_vat = True
362 break
363
364 if check_vat and hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
365 check = getattr(partner_obj, 'check_vat_' + vat_country.lower())
366 vat_ok = check(vat)
367 else:
368 vat_ok = False
369
370 if not vat_ok and 'country_id' in data_record['billing_address'] and hasattr(partner_obj, 'check_vat_' + vat_country.lower()):
356 # Maybe magento vat number has not country code prefix. Take it from billing address.371 # Maybe magento vat number has not country code prefix. Take it from billing address.
357 check = getattr(partner_obj, 'check_vat_' + data_record['billing_address']['country_id'].lower())372 check = getattr(partner_obj, 'check_vat_' + data_record['billing_address']['country_id'].lower())
358 vat_ok = check(vat)373 vat_ok = check(vat)
359 vat = data_record['billing_address']['country_id'] + vat374 vat = data_record['billing_address']['country_id'] + vat
360 if vat_ok: 375
361 partner_obj.write(cr, uid, [partner_id], {'vat_subjected':True, 'vat':vat})376 if vat_ok:
377 partner_obj.write(cr, uid, [partner_id], {'vat_subjected':True, 'vat':(vat_country+vat).upper()})
378
362 return res379 return res
363 380
364 def get_order_lines(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context):381 def get_order_lines(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context):
365382
=== modified file 'sale_view.xml'
--- sale_view.xml 2011-01-18 17:37:25 +0000
+++ sale_view.xml 2011-02-24 10:57:58 +0000
@@ -61,8 +61,10 @@
61 <page string="Magento Information">61 <page string="Magento Information">
62 <field name="magento_shop" />62 <field name="magento_shop" />
63 <field name="auto_import" />63 <field name="auto_import" />
64 <field name="allow_magento_order_status_push" />64 <field name="allow_magento_order_status_push" />
65 <field name="allow_magento_notification" attrs="{'invisible':[('allow_magento_order_status_push','=',False)]}"/>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"/>
66 </page>68 </page>
67 </xpath>69 </xpath>
68 </field>70 </field>