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

Proposed by arthru
Status: Merged
Merged at revision: 277
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 Approve
arthru Needs Resubmitting
Review via email: mp+193024@code.launchpad.net

This proposal supersedes a proposal from 2013-10-25.

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.
Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote : Posted in a previous version of this proposal

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)
Revision history for this message
arthru (arthru) wrote :

I've merged the patch from Romain Deheele (Thanks !).

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

Hi,

Thanks for the merge.
I've manually tested it again, it's ok.

Romain

review: Approve (code review and test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'prestashoperpconnect/prestashop_model.py'
2--- prestashoperpconnect/prestashop_model.py 2013-10-13 20:52:13 +0000
3+++ prestashoperpconnect/prestashop_model.py 2013-10-29 09:36:51 +0000
4@@ -75,7 +75,7 @@
5 required=True,
6 help='Warehouse used to compute the stock quantities.'
7 ),
8- # add a field `auto_activate` -> activate a cron
9+ 'taxes_included': fields.boolean("Use tax included prices"),
10 'import_partners_since': fields.datetime('Import partners since'),
11 'import_orders_since': fields.datetime('Import Orders since'),
12 'language_ids': fields.one2many(
13
14=== modified file 'prestashoperpconnect/prestashop_model_view.xml'
15--- prestashoperpconnect/prestashop_model_view.xml 2013-08-14 16:42:54 +0000
16+++ prestashoperpconnect/prestashop_model_view.xml 2013-10-29 09:36:51 +0000
17@@ -41,6 +41,7 @@
18 </group>
19 <group name="main_configuration" string="Main Configuration">
20 <field name="warehouse_id"/>
21+ <field name="taxes_included"/>
22 </group>
23 <notebook>
24 <page name="import" string="Imports">
25
26=== modified file 'prestashoperpconnect/unit/direct_binder.py'
27--- prestashoperpconnect/unit/direct_binder.py 2013-05-13 09:51:15 +0000
28+++ prestashoperpconnect/unit/direct_binder.py 2013-10-29 09:36:51 +0000
29@@ -200,6 +200,8 @@
30 _ps_field = 'rate'
31
32 def _compare_function(self, ps_val, erp_val, ps_dict, erp_dict):
33- if erp_dict['type_tax_use'] == 'sale' and \
34+ taxes_inclusion_test = self.backend_record.taxes_included and \
35+ erp_dict['price_include'] or not erp_dict['price_include']
36+ if taxes_inclusion_test and erp_dict['type_tax_use'] == 'sale' and \
37 abs(erp_val*100 - float(ps_val)) < 0.01:
38 return True
39
40=== modified file 'prestashoperpconnect/unit/mapper.py'
41--- prestashoperpconnect/unit/mapper.py 2013-10-25 12:41:52 +0000
42+++ prestashoperpconnect/unit/mapper.py 2013-10-29 09:36:51 +0000
43@@ -22,6 +22,7 @@
44 # along with this program. If not, see <http://www.gnu.org/licenses/>.
45 #
46 ##############################################################################
47+from decimal import Decimal
48
49 from openerp.tools.translate import _
50 from openerp.addons.connector.unit.mapper import (
51@@ -388,16 +389,19 @@
52
53 def _after_mapping(self, result):
54 sess = self.session
55+ backend = self.backend_record
56 order_line_ids = []
57 if 'prestashop_order_line_ids' in result:
58 order_line_ids = result['prestashop_order_line_ids']
59- result = sess.pool['sale.order']._convert_special_fields(
60- sess.cr,
61- sess.uid,
62- result,
63- order_line_ids,
64- sess.context
65- )
66+ taxes_included = backend.taxes_included
67+ with self.session.change_context({'is_tax_included': taxes_included}):
68+ result = sess.pool['sale.order']._convert_special_fields(
69+ sess.cr,
70+ sess.uid,
71+ result,
72+ order_line_ids,
73+ sess.context
74+ )
75 onchange = self.get_connector_unit_for_model(SaleOrderOnChange)
76 order_line_ids = []
77 if 'prestashop_order_line_ids' in result:
78@@ -412,12 +416,25 @@
79 direct = [
80 ('product_name', 'name'),
81 ('id', 'sequence'),
82- ('product_price', 'price_unit'),
83 ('product_quantity', 'product_uom_qty'),
84 ('reduction_percent', 'discount'),
85 ]
86
87 @mapping
88+ def price_unit(self, record):
89+ if self.backend_record.taxes_included:
90+ key = 'unit_price_tax_incl'
91+ else:
92+ key = 'unit_price_tax_excl'
93+ if record['reduction_percent']:
94+ reduction = Decimal(record['reduction_percent'])
95+ price = Decimal(record[key])
96+ price_unit = price / ((100 - reduction) / 100)
97+ else:
98+ price_unit = record[key]
99+ return {'price_unit': price_unit}
100+
101+ @mapping
102 def product_id(self, record):
103 return {'product_id': self.get_openerp_id(
104 'prestashop.product.product',