Merge lp:~openerp-connector-core-editors/openerp-connector/7.0-e-commerce-addons-refactor-so-extra-lines into lp:openerp-connector/7.0-e-commerce-addons

Proposed by Guewen Baconnier @ Camptocamp
Status: Rejected
Rejected by: Guewen Baconnier @ Camptocamp
Proposed branch: lp:~openerp-connector-core-editors/openerp-connector/7.0-e-commerce-addons-refactor-so-extra-lines
Merge into: lp:openerp-connector/7.0-e-commerce-addons
Diff against target: 149 lines (+99/-1)
2 files modified
connector_ecommerce/product.py (+4/-0)
connector_ecommerce/sale.py (+95/-1)
To merge this branch: bzr merge lp:~openerp-connector-core-editors/openerp-connector/7.0-e-commerce-addons-refactor-so-extra-lines
Reviewer Review Type Date Requested Status
OpenERP Connector Core Editors Pending
Review via email: mp+194629@code.launchpad.net

Description of the change

Refactoring of the legacy code for shipping costs, cash on delivery, gift certificates.

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

Branch is now sufficiently stable to be tested and used for development.

344. By Guewen Baconnier @ Camptocamp

[FIX] 'int' object is not iterable error

345. By Guewen Baconnier @ Camptocamp

[FIX] 'int' object is not iterable error, again

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Has been included in the new branch lp:openerp-connector-ecommerce

Unmerged revisions

345. By Guewen Baconnier @ Camptocamp

[FIX] 'int' object is not iterable error, again

344. By Guewen Baconnier @ Camptocamp

[FIX] 'int' object is not iterable error

343. By Guewen Baconnier @ Camptocamp

[MRG] sync with master branch

342. By Guewen Baconnier @ Camptocamp

[MRG] propagate the 'shop_id' in the context if it exists so the fiscal position rules (from openerp-fiscal-rules' project) can apply automatically

(in line with https://code.launchpad.net/\~camptocamp/openerp-connector/7.0-e-commerce-addons-fiscal-rules-compat/+merge/197384\)

341. By Guewen Baconnier @ Camptocamp

[FIX] in lines builders, product_ref is not mandatory if we provide a product, renames 'product_id' to 'product', keeping ambiguity as we can have an int or browse_record.

340. By Guewen Baconnier @ Camptocamp

[MRG] from master

339. By Guewen Baconnier @ Camptocamp

[FIX] simplify last change

338. By Guewen Baconnier @ Camptocamp

[FIX] Sales Orders onchanges: allow to have lines with other commands than (0, 0, {values}).

337. By Guewen Baconnier @ Camptocamp

[IMP] allow to use a product id or a product browse_record in lines builders

336. By Guewen Baconnier @ Camptocamp

[ADD] deprecation warning

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'connector_ecommerce/product.py'
--- connector_ecommerce/product.py 2013-11-01 16:11:23 +0000
+++ connector_ecommerce/product.py 2013-12-10 10:13:58 +0000
@@ -82,6 +82,8 @@
82 prod_id)82 prod_id)
8383
84 def write(self, cr, uid, ids, vals, context=None):84 def write(self, cr, uid, ids, vals, context=None):
85 if isinstance(ids, (int, long)):
86 ids = [ids]
85 result = super(product_template, self).write(cr, uid, ids,87 result = super(product_template, self).write(cr, uid, ids,
86 vals, context=context)88 vals, context=context)
87 self._price_changed(cr, uid, ids, vals, context=context)89 self._price_changed(cr, uid, ids, vals, context=context)
@@ -134,6 +136,8 @@
134 def write(self, cr, uid, ids, vals, context=None):136 def write(self, cr, uid, ids, vals, context=None):
135 if context is None:137 if context is None:
136 context = {}138 context = {}
139 if isinstance(ids, (int, long)):
140 ids = [ids]
137 context = context.copy()141 context = context.copy()
138 context['from_product_ids'] = ids142 context['from_product_ids'] = ids
139 result = super(product_product, self).write(143 result = super(product_product, self).write(
140144
=== modified file 'connector_ecommerce/sale.py'
--- connector_ecommerce/sale.py 2013-07-15 14:29:14 +0000
+++ connector_ecommerce/sale.py 2013-12-10 10:13:58 +0000
@@ -21,9 +21,14 @@
21#21#
22##############################################################################22##############################################################################
2323
24import logging
25
24from openerp.osv import orm, fields, osv26from openerp.osv import orm, fields, osv
25from openerp.tools.translate import _27from openerp.tools.translate import _
26from openerp import netsvc28from openerp import netsvc
29from openerp.addons.connector.connector import ConnectorUnit
30
31_logger = logging.getLogger(__name__)
2732
2833
29class sale_shop(orm.Model):34class sale_shop(orm.Model):
@@ -301,6 +306,9 @@
301 :return: the value for the sale order with the special field converted306 :return: the value for the sale order with the special field converted
302 :rtype: dict307 :rtype: dict
303 """308 """
309 _logger.warning('sale_order._convert_special_fields() has been '
310 'deprecated. Use a specialized '
311 'SpecialOrderLineBuilder class instead.')
304 shipping_fields = ['shipping_amount_tax_excluded',312 shipping_fields = ['shipping_amount_tax_excluded',
305 'shipping_amount_tax_included',313 'shipping_amount_tax_included',
306 'shipping_tax_amount']314 'shipping_tax_amount']
@@ -396,7 +404,6 @@
396 extra_line['name'] = "%s [%s]" % (extra_line['name'],404 extra_line['name'] = "%s [%s]" % (extra_line['name'],
397 vals[ext_code_field])405 vals[ext_code_field])
398 vals['order_line'].append((0, 0, extra_line))406 vals['order_line'].append((0, 0, extra_line))
399
400 return self._clean_special_fields(option, vals)407 return self._clean_special_fields(option, vals)
401408
402 def _clean_special_fields(self, option, vals):409 def _clean_special_fields(self, option, vals):
@@ -406,3 +413,90 @@
406 if option.get(key) and option[key] in vals:413 if option.get(key) and option[key] in vals:
407 del vals[option[key]]414 del vals[option[key]]
408 return vals # if there is no price, we have nothing to import415 return vals # if there is no price, we have nothing to import
416
417
418class SpecialOrderLineBuilder(ConnectorUnit):
419 """ Base class to build a sale order line for a sale order
420
421 Used when extra order lines have to be added in a sale order
422 but we only know some parameters (product, price, ...), for instance,
423 a line for the shipping costs or the gift coupons.
424
425 It can be subclassed to customize the way the lines are created.
426
427 Usage::
428
429 builder = self.get_connector_for_unit(ShippingLineBuilder,
430 model='sale.order.line')
431 builder.price_unit = 100
432 builder.get_line()
433
434 """
435 _model_name = None
436
437 def __init__(self, environment):
438 super(SpecialOrderLineBuilder, self).__init__(environment)
439 self.product = None # id or browse_record
440 # when no product_id, fallback to a product_ref
441 self.product_ref = None # tuple (module, xmlid)
442 self.price_unit = None
443 self.quantity = 1
444 self.sign = 1
445
446 def get_line(self):
447 assert self.product_ref or self.product
448 assert self.price_unit is not None
449 line = {}
450 session = self.session
451
452 product = product_id = self.product
453 if product_id is None:
454 model_data_obj = session.pool.get('ir.model.data')
455 __, product_id = model_data_obj.get_object_reference(
456 session.cr, session.uid, *self.product_ref)
457
458 if not isinstance(product_id, orm.browse_record):
459 product = session.browse('product.product', product_id)
460 return {'product_id': product.id,
461 'name': product.name,
462 'product_uom': product.uom_id.id,
463 'product_uom_qty': self.quantity,
464 'price_unit': self.price_unit * self.sign}
465
466
467class ShippingLineBuilder(SpecialOrderLineBuilder):
468 """ Return values for a Shipping line """
469 _model_name = None
470
471 def __init__(self, environment):
472 super(ShippingLineBuilder, self).__init__(environment)
473 self.product_ref = ('connector_ecommerce', 'product_product_shipping')
474
475
476class CashOnDeliveryLineBuilder(SpecialOrderLineBuilder):
477 """ Return values for a Cash on Delivery line """
478 _model_name = None
479 _model_name = None
480
481 def __init__(self, environment):
482 super(CashOnDeliveryLineBuilder, self).__init__(environment)
483 self.product_ref = ('connector_ecommerce',
484 'product_product_cash_on_delivery')
485
486
487class GiftOrderLineBuilder(SpecialOrderLineBuilder):
488 """ Return values for a Gift line """
489 _model_name = None
490
491 def __init__(self, environment):
492 super(GiftOrderLineBuilder, self).__init__(environment)
493 self.product_ref = ('connector_ecommerce',
494 'product_product_gift')
495 self.sign = -1
496 self.gift_code = None
497
498 def get_line(self):
499 line = super(GiftOrderLineBuilder, self).get_line()
500 if self.gift_code:
501 line['name'] = "%s [%s]" % (line['name'], self.gift_code)
502 return line

Subscribers

People subscribed via source and target branches