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 on 2013-11-09
Status: Rejected
Rejected by: Guewen Baconnier @ Camptocamp on 2014-02-04
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 2013-11-09 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.

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

344. By Guewen Baconnier @ Camptocamp on 2013-12-10

[FIX] 'int' object is not iterable error

345. By Guewen Baconnier @ Camptocamp on 2013-12-10

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

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

Unmerged revisions

345. By Guewen Baconnier @ Camptocamp on 2013-12-10

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

344. By Guewen Baconnier @ Camptocamp on 2013-12-10

[FIX] 'int' object is not iterable error

343. By Guewen Baconnier @ Camptocamp on 2013-12-09

[MRG] sync with master branch

342. By Guewen Baconnier @ Camptocamp on 2013-12-02

[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 on 2013-11-26

[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 on 2013-11-13

[MRG] from master

339. By Guewen Baconnier @ Camptocamp on 2013-11-12

[FIX] simplify last change

338. By Guewen Baconnier @ Camptocamp on 2013-11-12

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

337. By Guewen Baconnier @ Camptocamp on 2013-11-09

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

336. By Guewen Baconnier @ Camptocamp on 2013-11-09

[ADD] deprecation warning

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'connector_ecommerce/product.py'
2--- connector_ecommerce/product.py 2013-11-01 16:11:23 +0000
3+++ connector_ecommerce/product.py 2013-12-10 10:13:58 +0000
4@@ -82,6 +82,8 @@
5 prod_id)
6
7 def write(self, cr, uid, ids, vals, context=None):
8+ if isinstance(ids, (int, long)):
9+ ids = [ids]
10 result = super(product_template, self).write(cr, uid, ids,
11 vals, context=context)
12 self._price_changed(cr, uid, ids, vals, context=context)
13@@ -134,6 +136,8 @@
14 def write(self, cr, uid, ids, vals, context=None):
15 if context is None:
16 context = {}
17+ if isinstance(ids, (int, long)):
18+ ids = [ids]
19 context = context.copy()
20 context['from_product_ids'] = ids
21 result = super(product_product, self).write(
22
23=== modified file 'connector_ecommerce/sale.py'
24--- connector_ecommerce/sale.py 2013-07-15 14:29:14 +0000
25+++ connector_ecommerce/sale.py 2013-12-10 10:13:58 +0000
26@@ -21,9 +21,14 @@
27 #
28 ##############################################################################
29
30+import logging
31+
32 from openerp.osv import orm, fields, osv
33 from openerp.tools.translate import _
34 from openerp import netsvc
35+from openerp.addons.connector.connector import ConnectorUnit
36+
37+_logger = logging.getLogger(__name__)
38
39
40 class sale_shop(orm.Model):
41@@ -301,6 +306,9 @@
42 :return: the value for the sale order with the special field converted
43 :rtype: dict
44 """
45+ _logger.warning('sale_order._convert_special_fields() has been '
46+ 'deprecated. Use a specialized '
47+ 'SpecialOrderLineBuilder class instead.')
48 shipping_fields = ['shipping_amount_tax_excluded',
49 'shipping_amount_tax_included',
50 'shipping_tax_amount']
51@@ -396,7 +404,6 @@
52 extra_line['name'] = "%s [%s]" % (extra_line['name'],
53 vals[ext_code_field])
54 vals['order_line'].append((0, 0, extra_line))
55-
56 return self._clean_special_fields(option, vals)
57
58 def _clean_special_fields(self, option, vals):
59@@ -406,3 +413,90 @@
60 if option.get(key) and option[key] in vals:
61 del vals[option[key]]
62 return vals # if there is no price, we have nothing to import
63+
64+
65+class SpecialOrderLineBuilder(ConnectorUnit):
66+ """ Base class to build a sale order line for a sale order
67+
68+ Used when extra order lines have to be added in a sale order
69+ but we only know some parameters (product, price, ...), for instance,
70+ a line for the shipping costs or the gift coupons.
71+
72+ It can be subclassed to customize the way the lines are created.
73+
74+ Usage::
75+
76+ builder = self.get_connector_for_unit(ShippingLineBuilder,
77+ model='sale.order.line')
78+ builder.price_unit = 100
79+ builder.get_line()
80+
81+ """
82+ _model_name = None
83+
84+ def __init__(self, environment):
85+ super(SpecialOrderLineBuilder, self).__init__(environment)
86+ self.product = None # id or browse_record
87+ # when no product_id, fallback to a product_ref
88+ self.product_ref = None # tuple (module, xmlid)
89+ self.price_unit = None
90+ self.quantity = 1
91+ self.sign = 1
92+
93+ def get_line(self):
94+ assert self.product_ref or self.product
95+ assert self.price_unit is not None
96+ line = {}
97+ session = self.session
98+
99+ product = product_id = self.product
100+ if product_id is None:
101+ model_data_obj = session.pool.get('ir.model.data')
102+ __, product_id = model_data_obj.get_object_reference(
103+ session.cr, session.uid, *self.product_ref)
104+
105+ if not isinstance(product_id, orm.browse_record):
106+ product = session.browse('product.product', product_id)
107+ return {'product_id': product.id,
108+ 'name': product.name,
109+ 'product_uom': product.uom_id.id,
110+ 'product_uom_qty': self.quantity,
111+ 'price_unit': self.price_unit * self.sign}
112+
113+
114+class ShippingLineBuilder(SpecialOrderLineBuilder):
115+ """ Return values for a Shipping line """
116+ _model_name = None
117+
118+ def __init__(self, environment):
119+ super(ShippingLineBuilder, self).__init__(environment)
120+ self.product_ref = ('connector_ecommerce', 'product_product_shipping')
121+
122+
123+class CashOnDeliveryLineBuilder(SpecialOrderLineBuilder):
124+ """ Return values for a Cash on Delivery line """
125+ _model_name = None
126+ _model_name = None
127+
128+ def __init__(self, environment):
129+ super(CashOnDeliveryLineBuilder, self).__init__(environment)
130+ self.product_ref = ('connector_ecommerce',
131+ 'product_product_cash_on_delivery')
132+
133+
134+class GiftOrderLineBuilder(SpecialOrderLineBuilder):
135+ """ Return values for a Gift line """
136+ _model_name = None
137+
138+ def __init__(self, environment):
139+ super(GiftOrderLineBuilder, self).__init__(environment)
140+ self.product_ref = ('connector_ecommerce',
141+ 'product_product_gift')
142+ self.sign = -1
143+ self.gift_code = None
144+
145+ def get_line(self):
146+ line = super(GiftOrderLineBuilder, self).get_line()
147+ if self.gift_code:
148+ line['name'] = "%s [%s]" % (line['name'], self.gift_code)
149+ return line

Subscribers

People subscribed via source and target branches