~prestashoperpconnect-core-editors/prestashoperpconnect/7.0

« back to all changes in this revision

Viewing changes to prestashoperpconnect/unit/mapper.py

  • Committer: Arthur Vuillard
  • Date: 2013-10-29 14:45:33 UTC
  • mfrom: (272.1.5 prestashoperpconnect-ttc)
  • Revision ID: arthur.vuillard@akretion.com-20131029144533-kwib1ycmxvg63ho6
MergeĀ fromĀ lp:~arthru/prestashoperpconnect/tax-included-in-prices

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
23
#
24
24
##############################################################################
 
25
from decimal import Decimal
25
26
 
26
27
from openerp.tools.translate import _
27
28
from openerp.addons.connector.unit.mapper import (
388
389
 
389
390
    def _after_mapping(self, result):
390
391
        sess = self.session
 
392
        backend = self.backend_record
391
393
        order_line_ids = []
392
394
        if 'prestashop_order_line_ids' in result:
393
395
            order_line_ids = result['prestashop_order_line_ids']
394
 
        result = sess.pool['sale.order']._convert_special_fields(
395
 
            sess.cr,
396
 
            sess.uid,
397
 
            result,
398
 
            order_line_ids,
399
 
            sess.context
400
 
        )
 
396
        taxes_included = backend.taxes_included
 
397
        with self.session.change_context({'is_tax_included': taxes_included}):
 
398
            result = sess.pool['sale.order']._convert_special_fields(
 
399
                sess.cr,
 
400
                sess.uid,
 
401
                result,
 
402
                order_line_ids,
 
403
                sess.context
 
404
            )
401
405
        onchange = self.get_connector_unit_for_model(SaleOrderOnChange)
402
406
        order_line_ids = []
403
407
        if 'prestashop_order_line_ids' in result:
412
416
    direct = [
413
417
        ('product_name', 'name'),
414
418
        ('id', 'sequence'),
415
 
        ('product_price', 'price_unit'),
416
419
        ('product_quantity', 'product_uom_qty'),
417
420
        ('reduction_percent', 'discount'),
418
421
    ]
419
422
 
420
423
    @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
438
    def product_id(self, record):
422
439
        return {'product_id': self.get_openerp_id(
423
440
            'prestashop.product.product',