Merge lp:~camptocamp/openerp-connector-magento/7.0-magentoerpconnect-handle-shipping-tax-in-tax_included-context-rde into lp:~openerp-connector-core-editors/openerp-connector-magento/7.0

Proposed by Romain Deheele - Camptocamp
Status: Merged
Merged at revision: 942
Proposed branch: lp:~camptocamp/openerp-connector-magento/7.0-magentoerpconnect-handle-shipping-tax-in-tax_included-context-rde
Merge into: lp:~openerp-connector-core-editors/openerp-connector-magento/7.0
Diff against target: 447 lines (+413/-6)
3 files modified
magentoerpconnect/sale.py (+9/-5)
magentoerpconnect/tests/test_data.py (+373/-0)
magentoerpconnect/tests/test_synchronization.py (+31/-1)
To merge this branch: bzr merge lp:~camptocamp/openerp-connector-magento/7.0-magentoerpconnect-handle-shipping-tax-in-tax_included-context-rde
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+193927@code.launchpad.net

Description of the change

Hello,

This merge proposal concerns
https://bugs.launchpad.net/openerp-connector/+bug/1234117
and has been started here:
https://code.launchpad.net/~camptocamp/openerp-connector/7.0-magentoerpconnect-handle-shipping-tax-in-tax_included-context/+merge/189592
But I create a new cleaner merge proposal (the previous has some text conflicts)

It includes:
-better tax included management
-unit test

Romain

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks a lot!
LGTM

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magentoerpconnect/sale.py'
--- magentoerpconnect/sale.py 2013-10-30 13:15:07 +0000
+++ magentoerpconnect/sale.py 2013-11-05 13:59:19 +0000
@@ -675,11 +675,15 @@
675 sess = self.session675 sess = self.session
676 # TODO: refactor: do no longer store the transient fields in the676 # TODO: refactor: do no longer store the transient fields in the
677 # result, use a ConnectorUnit to create the lines677 # result, use a ConnectorUnit to create the lines
678 result = sess.pool['sale.order']._convert_special_fields(sess.cr,678 backend = self.backend_record
679 sess.uid,679 # in tax_included context, need to pass it in context
680 result,680 tax_included = backend.catalog_price_tax_included
681 result['magento_order_line_ids'],681 with self.session.change_context({'is_tax_included': tax_included}):
682 sess.context)682 result = sess.pool['sale.order']._convert_special_fields(sess.cr,
683 sess.uid,
684 result,
685 result['magento_order_line_ids'],
686 sess.context)
683 # remove transient fields otherwise OpenERP will raise a warning687 # remove transient fields otherwise OpenERP will raise a warning
684 # or even fail to create the record because the fields do not688 # or even fail to create the record because the fields do not
685 # exist689 # exist
686690
=== modified file 'magentoerpconnect/tests/test_data.py'
--- magentoerpconnect/tests/test_data.py 2013-10-30 13:16:37 +0000
+++ magentoerpconnect/tests/test_data.py 2013-11-05 13:59:19 +0000
@@ -25398,4 +25398,377 @@
25398 'updated_at': '2013-10-30 09:43:20',25398 'updated_at': '2013-10-30 09:43:20',
25399 'weight': '2.0000',25399 'weight': '2.0000',
25400 'x_forwarded_for': None},25400 'x_forwarded_for': None},
25401('sales_order.info', (900000695, None)): {'adjustment_negative': None,
25402 'adjustment_positive': None,
25403 'applied_rule_ids': None,
25404 'base_adjustment_negative': None,
25405 'base_adjustment_positive': None,
25406 'base_currency_code': 'EUR',
25407 'base_discount_amount': '0.0000',
25408 'base_discount_canceled': None,
25409 'base_discount_invoiced': '0.0000',
25410 'base_discount_refunded': None,
25411 'base_grand_total': '97.5000',
25412 'base_hidden_tax_amount': '0.0000',
25413 'base_hidden_tax_invoiced': '0.0000',
25414 'base_hidden_tax_refunded': None,
25415 'base_shipping_amount': '7.8700',
25416 'base_shipping_canceled': None,
25417 'base_shipping_discount_amount': '0.0000',
25418 'base_shipping_hidden_tax_amnt': '0.0000',
25419 'base_shipping_hidden_tax_amount': '0.0000',
25420 'base_shipping_incl_tax': '8.5000',
25421 'base_shipping_invoiced': '7.8700',
25422 'base_shipping_refunded': None,
25423 'base_shipping_tax_amount': '0.6300',
25424 'base_shipping_tax_refunded': None,
25425 'base_subtotal': '82.4100',
25426 'base_subtotal_canceled': None,
25427 'base_subtotal_incl_tax': '89.0000',
25428 'base_subtotal_invoiced': '82.4100',
25429 'base_subtotal_refunded': None,
25430 'base_tax_amount': '7.2200',
25431 'base_tax_canceled': None,
25432 'base_tax_invoiced': '7.2200',
25433 'base_tax_refunded': None,
25434 'base_to_global_rate': '1.0000',
25435 'base_to_order_rate': '1.0000',
25436 'base_total_canceled': None,
25437 'base_total_due': '0.0000',
25438 'base_total_invoiced': '97.5000',
25439 'base_total_invoiced_cost': '0.0000',
25440 'base_total_offline_refunded': None,
25441 'base_total_online_refunded': None,
25442 'base_total_paid': '97.5000',
25443 'base_total_qty_ordered': None,
25444 'base_total_refunded': None,
25445 'billing_address': {'address_id': '38468',
25446 'address_type': 'billing',
25447 'city': 'Lyon',
25448 'company': None,
25449 'country_id': 'FR',
25450 'customer_address_id': '4999',
25451 'customer_id': None,
25452 'email': 'john@doe.fr',
25453 'fax': None,
25454 'firstname': 'John',
25455 'lastname': 'Doe',
25456 'middlename': None,
25457 'parent_id': '7360',
25458 'postcode': '1006',
25459 'prefix': None,
25460 'quote_address_id': None,
25461 'region': None,
25462 'region_id': None,
25463 'street': 'Victor Hugo',
25464 'suffix': None,
25465 'telephone': '31763163390',
25466 'vat_id': None,
25467 'vat_is_valid': None,
25468 'vat_request_date': None,
25469 'vat_request_id': None,
25470 'vat_request_success': None},
25471 'billing_address_id': '38468',
25472 'can_ship_partially': None,
25473 'can_ship_partially_item': None,
25474 'coupon_code': None,
25475 'coupon_rule_name': None,
25476 'created_at': '2013-10-14 13:20:56',
25477 'customer_dob': None,
25478 'customer_email': 'john@doe.fr',
25479 'customer_firstname': 'John',
25480 'customer_gender': None,
25481 'customer_group_id': '1',
25482 'customer_id': '1',
25483 'customer_is_guest': '0',
25484 'customer_lastname': 'Doe',
25485 'customer_middlename': None,
25486 'customer_note': None,
25487 'customer_note_notify': '1',
25488 'customer_prefix': None,
25489 'customer_suffix': None,
25490 'customer_taxvat': None,
25491 'discount_amount': '0.0000',
25492 'discount_canceled': None,
25493 'discount_description': None,
25494 'discount_invoiced': '0.0000',
25495 'discount_refunded': None,
25496 'edit_increment': None,
25497 'email_sent': '1',
25498 'employee_email': None,
25499 'employee_name': None,
25500 'employee_phone': None,
25501 'ext_customer_id': None,
25502 'ext_order_id': None,
25503 'forced_do_shipment_with_invoice': None,
25504 'forced_shipment_with_invoice': None,
25505 'gift_message_id': None,
25506 'global_currency_code': 'EUR',
25507 'grand_total': '97.5000',
25508 'hidden_tax_amount': '0.0000',
25509 'hidden_tax_invoiced': '0.0000',
25510 'hidden_tax_refunded': None,
25511 'hold_before_state': None,
25512 'hold_before_status': None,
25513 'imported': '0',
25514 'increment_id': '100005281',
25515 'is_virtual': '0',
25516 'items': [{'additional_data': None,
25517 'amount_refunded': '0.0000',
25518 'applied_rule_ids': None,
25519 'base_amount_refunded': '0.0000',
25520 'base_cost': None,
25521 'base_discount_amount': '0.0000',
25522 'base_discount_invoiced': '0.0000',
25523 'base_discount_refunded': None,
25524 'base_hidden_tax_amount': None,
25525 'base_hidden_tax_invoiced': '0.0000',
25526 'base_hidden_tax_refunded': None,
25527 'base_original_price': '89.0000',
25528 'base_price': '82.4100',
25529 'base_price_incl_tax': '89.0000',
25530 'base_row_invoiced': '82.4100',
25531 'base_row_total': '82.4100',
25532 'base_row_total_incl_tax': '89.0000',
25533 'base_tax_amount': '6.5900',
25534 'base_tax_before_discount': None,
25535 'base_tax_invoiced': '6.5900',
25536 'base_tax_refunded': None,
25537 'base_weee_tax_applied_amount': '0.0000',
25538 'base_weee_tax_applied_row_amnt': '0.0000',
25539 'base_weee_tax_applied_row_amount': '0.0000',
25540 'base_weee_tax_disposition': '0.0000',
25541 'base_weee_tax_row_disposition': '0.0000',
25542 'created_at': '2013-10-14 13:20:56',
25543 'description': None,
25544 'discount_amount': '0.0000',
25545 'discount_invoiced': '0.0000',
25546 'discount_percent': '0.0000',
25547 'discount_refunded': None,
25548 'earned_points_hash': None,
25549 'ext_order_item_id': None,
25550 'free_shipping': '0',
25551 'gift_message_available': None,
25552 'gift_message_id': None,
25553 'hidden_tax_amount': None,
25554 'hidden_tax_canceled': None,
25555 'hidden_tax_invoiced': '0.0000',
25556 'hidden_tax_refunded': None,
25557 'is_nominal': '0',
25558 'is_qty_decimal': '0',
25559 'is_virtual': '0',
25560 'item_id': '12751',
25561 'locked_do_invoice': None,
25562 'locked_do_ship': None,
25563 'name': 'Dior Homme',
25564 'no_discount': '0',
25565 'order_id': '7360',
25566 'original_price': '89.0000',
25567 'parent_item_id': None,
25568 'price': '82.4100',
25569 'price_incl_tax': '89.0000',
25570 'product_id': '157',
25571 'product_options': 'a:1:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:176:"aHR0cDovL3d3dy4xMDAwcGFyZnVtcy5jaC9ib3V0aXF1ZTEuNy4wLjIvZnIvcGFyZnVtLWhvbW1lcy1ldC1mZW1tZXMtcGFzLWNoZXIvcGFyZnVtLWRpb3ItcGFzLWNoZXIvcGFyZnVtLWRpb3ItaG9tbWUtcGFzLWNoZXIuaHRtbA,,";s:7:"product";s:4:"4773";s:15:"related_product";s:0:"";s:3:"qty";s:1:"1";s:1:"x";s:2:"70";s:1:"y";s:2:"23";}}',
25572 'product_type': 'simple',
25573 'qty_backordered': None,
25574 'qty_canceled': '0.0000',
25575 'qty_invoiced': '1.0000',
25576 'qty_ordered': '1.0000',
25577 'qty_refunded': '0.0000',
25578 'qty_shipped': '0.0000',
25579 'quote_item_id': '46485',
25580 'redeemed_points_hash': None,
25581 'row_invoiced': '82.4100',
25582 'row_total': '82.4100',
25583 'row_total_after_redemptions': None,
25584 'row_total_after_redemptions_incl_tax': None,
25585 'row_total_before_redemptions': None,
25586 'row_total_before_redemptions_incl_tax': None,
25587 'row_total_incl_tax': '89.0000',
25588 'row_weight': '0.0000',
25589 'sku': '1625',
25590 'store_id': '1',
25591 'tax_amount': '6.5900',
25592 'tax_before_discount': None,
25593 'tax_canceled': None,
25594 'tax_invoiced': '6.5900',
25595 'tax_percent': '8.0000',
25596 'tax_refunded': None,
25597 'updated_at': '2013-10-14 13:22:00',
25598 'weee_tax_applied': 'a:0:{}',
25599 'weee_tax_applied_amount': '0.0000',
25600 'weee_tax_applied_row_amount': '0.0000',
25601 'weee_tax_disposition': '0.0000',
25602 'weee_tax_row_disposition': '0.0000',
25603 'weight': None}],
25604 'order_currency_code': 'EUR',
25605 'order_id': '7360',
25606 'original_increment_id': None,
25607 'payment': {'account_status': None,
25608 'additional_data': None,
25609 'address_status': None,
25610 'amount_authorized': None,
25611 'amount_canceled': None,
25612 'amount_ordered': '97.5000',
25613 'amount_paid': '97.5000',
25614 'amount_refunded': None,
25615 'anet_trans_method': None,
25616 'base_amount_authorized': None,
25617 'base_amount_canceled': None,
25618 'base_amount_ordered': '97.5000',
25619 'base_amount_paid': '97.5000',
25620 'base_amount_paid_online': None,
25621 'base_amount_refunded': None,
25622 'base_amount_refunded_online': None,
25623 'base_shipping_amount': '7.8700',
25624 'base_shipping_captured': '7.8700',
25625 'base_shipping_refunded': None,
25626 'cc_approval': None,
25627 'cc_avs_status': None,
25628 'cc_cid_status': None,
25629 'cc_debug_request_body': None,
25630 'cc_debug_response_body': None,
25631 'cc_debug_response_serialized': None,
25632 'cc_exp_month': '0',
25633 'cc_exp_year': '0',
25634 'cc_last4': None,
25635 'cc_number_enc': None,
25636 'cc_owner': None,
25637 'cc_secure_verify': None,
25638 'cc_ss_issue': None,
25639 'cc_ss_start_month': '0',
25640 'cc_ss_start_year': '0',
25641 'cc_status': None,
25642 'cc_status_description': None,
25643 'cc_trans_id': None,
25644 'cc_type': None,
25645 'cybersource_token': None,
25646 'echeck_account_name': None,
25647 'echeck_account_type': None,
25648 'echeck_bank_name': None,
25649 'echeck_routing_number': None,
25650 'echeck_type': None,
25651 'flo2cash_account_id': None,
25652 'ideal_issuer_id': None,
25653 'ideal_issuer_title': None,
25654 'ideal_transaction_checked': None,
25655 'last_trans_id': '1P06829259760661R',
25656 'method': 'checkmo',
25657 'parent_id': '7360',
25658 'paybox_question_number': None,
25659 'paybox_request_number': None,
25660 'payment_id': '32844',
25661 'po_number': None,
25662 'protection_eligibility': None,
25663 'quote_payment_id': None,
25664 'shipping_amount': '7.8700',
25665 'shipping_captured': '7.8700',
25666 'shipping_refunded': None},
25667 'payment_auth_expiration': None,
25668 'payment_authorization_amount': None,
25669 'payment_authorization_expiration': None,
25670 'paypal_ipn_customer_notified': None,
25671 'protect_code': '49accf',
25672 'quote_address_id': None,
25673 'quote_id': '33794',
25674 'relation_child_id': None,
25675 'relation_child_real_id': None,
25676 'relation_parent_id': None,
25677 'relation_parent_real_id': None,
25678 'remote_ip': None,
25679 'rewards_base_discount_amount': None,
25680 'rewards_base_discount_tax_amount': None,
25681 'rewards_discount_amount': None,
25682 'rewards_discount_tax_amount': None,
25683 'shipping_address': {'address_id': '38469',
25684 'address_type': 'shipping',
25685 'city': 'Lyon',
25686 'company': None,
25687 'country_id': 'FR',
25688 'customer_address_id': None,
25689 'customer_id': None,
25690 'email': 'john@doe.fr',
25691 'fax': None,
25692 'firstname': 'John',
25693 'lastname': 'Doe',
25694 'middlename': None,
25695 'parent_id': '7360',
25696 'postcode': '1006',
25697 'prefix': None,
25698 'quote_address_id': None,
25699 'region': None,
25700 'region_id': None,
25701 'street': 'Victor Hugo',
25702 'suffix': None,
25703 'telephone': '31763163390',
25704 'vat_id': None,
25705 'vat_is_valid': None,
25706 'vat_request_date': None,
25707 'vat_request_id': None,
25708 'vat_request_success': None},
25709 'shipping_address_id': '38469',
25710 'shipping_amount': '7.8700',
25711 'shipping_canceled': None,
25712 'shipping_description': 'La Poste',
25713 'shipping_discount_amount': '0.0000',
25714 'shipping_hidden_tax_amount': '0.0000',
25715 'shipping_incl_tax': '8.5000',
25716 'shipping_invoiced': '7.8700',
25717 'shipping_method': 'flatrate_flatrate',
25718 'shipping_refunded': None,
25719 'shipping_tax_amount': '0.6300',
25720 'shipping_tax_refunded': None,
25721 'state': 'processing',
25722 'status': 'processing',
25723 'status_history': [{'comment': u'Notifier le client pour la facture n\xb0100003489.',
25724 'created_at': '2013-10-14 13:22:02',
25725 'entity_name': 'invoice',
25726 'is_customer_notified': '1',
25727 'is_visible_on_front': '0',
25728 'parent_id': '7360',
25729 'status': 'processing',
25730 'store_id': '1'},
25731 {'comment': u'IPN "Completed". Registered notification about captured amount of 97,50\xa0EUR. Transaction ID: "1P06829259760661R".',
25732 'created_at': '2013-10-14 13:22:00',
25733 'entity_name': 'invoice',
25734 'is_customer_notified': '2',
25735 'is_visible_on_front': '0',
25736 'parent_id': '7360',
25737 'status': 'processing',
25738 'store_id': '1'},
25739 {'comment': None,
25740 'created_at': '2013-10-14 13:20:58',
25741 'entity_name': 'order',
25742 'is_customer_notified': '0',
25743 'is_visible_on_front': '0',
25744 'parent_id': '7360',
25745 'status': 'pending_payment',
25746 'store_id': '1'}],
25747 'store_currency_code': 'EUR',
25748 'store_id': '1',
25749 'store_name': u'France',
25750 'store_to_base_rate': '1.0000',
25751 'store_to_order_rate': '1.0000',
25752 'subtotal': '82.4100',
25753 'subtotal_canceled': None,
25754 'subtotal_incl_tax': '89.0000',
25755 'subtotal_invoiced': '82.4100',
25756 'subtotal_refunded': None,
25757 'tax_amount': '7.2200',
25758 'tax_canceled': None,
25759 'tax_invoiced': '7.2200',
25760 'tax_refunded': None,
25761 'total_canceled': None,
25762 'total_due': '0.0000',
25763 'total_invoiced': '97.5000',
25764 'total_item_count': '1',
25765 'total_offline_refunded': None,
25766 'total_online_refunded': None,
25767 'total_paid': '97.5000',
25768 'total_qty_ordered': '1.0000',
25769 'total_refunded': None,
25770 'updated_at': '2013-10-14 13:22:00',
25771 'website_id': u'1',
25772 'weight': '0.0000',
25773 'x_forwarded_for': None},
25401}25774}
2540225775
=== modified file 'magentoerpconnect/tests/test_synchronization.py'
--- magentoerpconnect/tests/test_synchronization.py 2013-10-31 08:10:45 +0000
+++ magentoerpconnect/tests/test_synchronization.py 2013-11-05 13:59:19 +0000
@@ -286,4 +286,34 @@
286 self.uid,286 self.uid,
287 order_line_id[0],287 order_line_id[0],
288 ['price_unit'])['price_unit']288 ['price_unit'])['price_unit']
289 self.assertEqual(price_unit, 41.0500)
290\ No newline at end of file289\ No newline at end of file
290 self.assertEqual(price_unit, 41.0500)
291
292 def test_34_import_sale_order_with_taxes_included(self):
293 """ Import a sale order with taxes included """
294 backend_id = self.backend_id
295 self.backend_model.write(self.cr, self.uid, self.backend_id,
296 {'catalog_price_tax_included': True})
297 with mock_api(magento_base_responses):
298 with mock_urlopen_image():
299 import_record(self.session,
300 'magento.sale.order',
301 backend_id, 900000695)
302 mag_order_model = self.registry('magento.sale.order')
303 mag_order_ids = mag_order_model.search(self.cr,
304 self.uid,
305 [('backend_id', '=', backend_id),
306 ('magento_id', '=', '900000695')])
307 self.assertEqual(len(mag_order_ids), 1)
308 order_id = mag_order_model.read(self.cr,
309 self.uid,
310 mag_order_ids[0],
311 ['openerp_id'])['openerp_id']
312 order_model = self.registry('sale.order')
313 amount_total = order_model.read(self.cr,
314 self.uid,
315 order_id[0],
316 ['amount_total'])['amount_total']
317 #97.5 is the amount_total if connector takes correctly included tax prices.
318 self.assertEqual(amount_total, 97.5000)
319 self.backend_model.write(self.cr, self.uid, self.backend_id,
320 {'catalog_price_tax_included': False})