Merge lp:~arthru/prestashoperpconnect/tax-included-in-prices into lp:prestashoperpconnect

Proposed by arthru
Status: Superseded
Proposed branch: lp:~arthru/prestashoperpconnect/tax-included-in-prices
Merge into: lp:prestashoperpconnect
Diff against target: 104 lines (+30/-10)
4 files modified
prestashoperpconnect/prestashop_model.py (+1/-1)
prestashoperpconnect/prestashop_model_view.xml (+1/-0)
prestashoperpconnect/unit/direct_binder.py (+3/-1)
prestashoperpconnect/unit/mapper.py (+25/-8)
To merge this branch: bzr merge lp:~arthru/prestashoperpconnect/tax-included-in-prices
Reviewer Review Type Date Requested Status
Romain Deheele - Camptocamp (community) code review and test Needs Fixing
Review via email: mp+192673@code.launchpad.net

This proposal has been superseded by a proposal from 2013-10-29.

Description of the change

This propose to either use tax included prices or tax excluded prices for order imports.

To post a comment you must log in.
274. By arthru

Fix a shitty issue with reduction and tax included|excluded price

275. By arthru

Remove tabulations

276. By arthru

Add a forgotten import

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Hi,

It works on classic sale order lines.
But price unit on shipping line is still tax excluded.

Romain

review: Needs Fixing (code review and test)
277. By Romain Deheele - Camptocamp

Merge from Romain Deheele

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'prestashoperpconnect/prestashop_model.py'
--- prestashoperpconnect/prestashop_model.py 2013-10-13 20:52:13 +0000
+++ prestashoperpconnect/prestashop_model.py 2013-10-29 09:34:35 +0000
@@ -75,7 +75,7 @@
75 required=True,75 required=True,
76 help='Warehouse used to compute the stock quantities.'76 help='Warehouse used to compute the stock quantities.'
77 ),77 ),
78 # add a field `auto_activate` -> activate a cron78 'taxes_included': fields.boolean("Use tax included prices"),
79 'import_partners_since': fields.datetime('Import partners since'),79 'import_partners_since': fields.datetime('Import partners since'),
80 'import_orders_since': fields.datetime('Import Orders since'),80 'import_orders_since': fields.datetime('Import Orders since'),
81 'language_ids': fields.one2many(81 'language_ids': fields.one2many(
8282
=== modified file 'prestashoperpconnect/prestashop_model_view.xml'
--- prestashoperpconnect/prestashop_model_view.xml 2013-08-14 16:42:54 +0000
+++ prestashoperpconnect/prestashop_model_view.xml 2013-10-29 09:34:35 +0000
@@ -41,6 +41,7 @@
41 </group>41 </group>
42 <group name="main_configuration" string="Main Configuration">42 <group name="main_configuration" string="Main Configuration">
43 <field name="warehouse_id"/>43 <field name="warehouse_id"/>
44 <field name="taxes_included"/>
44 </group>45 </group>
45 <notebook>46 <notebook>
46 <page name="import" string="Imports">47 <page name="import" string="Imports">
4748
=== modified file 'prestashoperpconnect/unit/direct_binder.py'
--- prestashoperpconnect/unit/direct_binder.py 2013-05-13 09:51:15 +0000
+++ prestashoperpconnect/unit/direct_binder.py 2013-10-29 09:34:35 +0000
@@ -200,6 +200,8 @@
200 _ps_field = 'rate'200 _ps_field = 'rate'
201201
202 def _compare_function(self, ps_val, erp_val, ps_dict, erp_dict):202 def _compare_function(self, ps_val, erp_val, ps_dict, erp_dict):
203 if erp_dict['type_tax_use'] == 'sale' and \203 taxes_inclusion_test = self.backend_record.taxes_included and \
204 erp_dict['price_include'] or not erp_dict['price_include']
205 if taxes_inclusion_test and erp_dict['type_tax_use'] == 'sale' and \
204 abs(erp_val*100 - float(ps_val)) < 0.01:206 abs(erp_val*100 - float(ps_val)) < 0.01:
205 return True207 return True
206208
=== modified file 'prestashoperpconnect/unit/mapper.py'
--- prestashoperpconnect/unit/mapper.py 2013-10-25 12:41:52 +0000
+++ prestashoperpconnect/unit/mapper.py 2013-10-29 09:34:35 +0000
@@ -22,6 +22,7 @@
22# along with this program. If not, see <http://www.gnu.org/licenses/>.22# along with this program. If not, see <http://www.gnu.org/licenses/>.
23#23#
24##############################################################################24##############################################################################
25from decimal import Decimal
2526
26from openerp.tools.translate import _27from openerp.tools.translate import _
27from openerp.addons.connector.unit.mapper import (28from openerp.addons.connector.unit.mapper import (
@@ -388,16 +389,19 @@
388389
389 def _after_mapping(self, result):390 def _after_mapping(self, result):
390 sess = self.session391 sess = self.session
392 backend = self.backend_record
391 order_line_ids = []393 order_line_ids = []
392 if 'prestashop_order_line_ids' in result:394 if 'prestashop_order_line_ids' in result:
393 order_line_ids = result['prestashop_order_line_ids']395 order_line_ids = result['prestashop_order_line_ids']
394 result = sess.pool['sale.order']._convert_special_fields(396 taxes_included = backend.taxes_included
395 sess.cr,397 with self.session.change_context({'is_tax_included': taxes_included}):
396 sess.uid,398 result = sess.pool['sale.order']._convert_special_fields(
397 result,399 sess.cr,
398 order_line_ids,400 sess.uid,
399 sess.context401 result,
400 )402 order_line_ids,
403 sess.context
404 )
401 onchange = self.get_connector_unit_for_model(SaleOrderOnChange)405 onchange = self.get_connector_unit_for_model(SaleOrderOnChange)
402 order_line_ids = []406 order_line_ids = []
403 if 'prestashop_order_line_ids' in result:407 if 'prestashop_order_line_ids' in result:
@@ -412,12 +416,25 @@
412 direct = [416 direct = [
413 ('product_name', 'name'),417 ('product_name', 'name'),
414 ('id', 'sequence'),418 ('id', 'sequence'),
415 ('product_price', 'price_unit'),
416 ('product_quantity', 'product_uom_qty'),419 ('product_quantity', 'product_uom_qty'),
417 ('reduction_percent', 'discount'),420 ('reduction_percent', 'discount'),
418 ]421 ]
419422
420 @mapping423 @mapping
424 def price_unit(self, record):
425 if self.backend_record.taxes_included:
426 key = 'unit_price_tax_incl'
427 else:
428 key = 'unit_price_tax_excl'
429 if record['reduction_percent']:
430 reduction = Decimal(record['reduction_percent'])
431 price = Decimal(record[key])
432 price_unit = price / ((100 - reduction) / 100)
433 else:
434 price_unit = record[key]
435 return {'price_unit': price_unit}
436
437 @mapping
421 def product_id(self, record):438 def product_id(self, record):
422 return {'product_id': self.get_openerp_id(439 return {'product_id': self.get_openerp_id(
423 'prestashop.product.product',440 'prestashop.product.product',