Merge lp:~openerp-dev/openobject-addons/trunk-bug-795487-uco into lp:openobject-addons

Proposed by Ujjvala Collins
Status: Merged
Merged at revision: 5423
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-795487-uco
Merge into: lp:openobject-addons
Diff against target: 264 lines (+68/-40)
5 files modified
product_visible_discount/product_visible_discount.py (+4/-3)
sale/sale.py (+59/-31)
sale/sale_view.xml (+2/-3)
sale_layout/sale_layout_view.xml (+1/-1)
warning/warning.py (+2/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-795487-uco
Reviewer Review Type Date Requested Status
Ujjvala Collins (community) Needs Resubmitting
qdp (OpenERP) Needs Fixing
Mustufa Rangwala (Open ERP) (community) Approve
Review via email: mp+65440@code.launchpad.net

Description of the change

[FIX] sale:
----------------
* Solved problem of packaging field not being empty on sale order line. (lp:795487)

To post a comment you must log in.
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

Your patch works for most of the cases with onchange from product and packaging.
But when you have already product on sale order line and you search for another products (you are not using backspace in this case) then it will not as expected.

Can you please check fix it ?

Thank you,
mra

review: Needs Fixing
Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello Sir,

I have fixed the said problem which was already there in the trunk too. Now it works according to the requirement. Please check.

Thanks.

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

you have updated the API method product_id_change on sale order line to put new context argument on it.
Rather changing the API we should add other onchange_packing instead of it.

With your patch if i install sale_margin module => sale order line breaks.

Thanks,
mra

review: Disapprove
Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello sir,

I have added a new onchange method for product packaging field as per your suggestion.

There is a change needed in "sale_layout" module too, as sale order view is being inherited and sale order line field is replaced, so I have changed the view accordingly.

Thanks,
Ujjvala

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

Ujjvala,

Your merge proposal working fine functionally as i have tested but need to fix few things in code:
- missing context on onchange_product_packings
- No need to create warning_msg variable, you can directly use it
- set default for flag=False on onchange_product_packings
- + warning = res.get('warning', {}) => fix this line as if there is warning from product onchange it will be override
- remove unused argument pricelist from onchange_product_packing
- + packaging = False
  + result['product_packaging'] = False
            should be packaging=result['product_packaging']=False

Thanks,
mra

review: Needs Fixing
Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello Sir,

I have fixed all the said problems. It works for all required cases.

Please check.

Thanks,
Ujjvala

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

i made small improvement.

review: Approve
Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello,

This merge proposal also solves the LP bug: 809491. I have added the missing argument for packaging while calling the super method in product_visible_discount module as suggested in the comment#3 on the bug report.

Thanks Paulius Sladkevičius - inovera.lt (komsas) for pointing the mistake.

Thanks,
Ujjvala

Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) :
review: Approve
Revision history for this message
qdp (OpenERP) (qdp) wrote :

please solve conflicts and ask for review again

review: Needs Fixing
Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello,

I have resolved conflicts. Can you please check again?

Thanks,
Ujjvala

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product_visible_discount/product_visible_discount.py'
2--- product_visible_discount/product_visible_discount.py 2011-02-01 14:25:28 +0000
3+++ product_visible_discount/product_visible_discount.py 2011-09-12 09:31:11 +0000
4@@ -40,7 +40,8 @@
5
6 def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
7 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
8- lang=False, update_tax=True,date_order=False,packaging=False,fiscal_position=False, flag=False):
9+ lang=False, update_tax=True, date_order=False, packaging=False,
10+ fiscal_position=False, flag=False, context=None):
11
12 def get_real_price(res_dict, product_id, qty, uom, pricelist):
13 item_obj = self.pool.get('product.pricelist.item')
14@@ -59,7 +60,7 @@
15 product_tmpl_id = product.product_tmpl_id.id
16
17 product_read = template_obj.read(cr, uid, product_tmpl_id, [field_name], context)
18-
19+
20 factor = 1.0
21 if uom and uom != product.uom_id.id:
22 product_uom_obj = self.pool.get('product.uom')
23@@ -70,7 +71,7 @@
24
25 res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
26 uom, qty_uos, uos, name, partner_id,
27- lang, update_tax,date_order,fiscal_position=fiscal_position,flag=flag)
28+ lang, update_tax, date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)
29
30 context = {'lang': lang, 'partner_id': partner_id}
31 result=res['value']
32
33=== modified file 'sale/sale.py'
34--- sale/sale.py 2011-09-04 16:59:39 +0000
35+++ sale/sale.py 2011-09-12 09:31:11 +0000
36@@ -105,11 +105,11 @@
37 procurement_order mp on (mp.move_id=m.id)
38 WHERE
39 p.sale_id IN %s GROUP BY m.state, mp.state, p.sale_id, p.type''', (tuple(ids),))
40-
41+
42 for item in cr.dictfetchall():
43 if item['move_state'] == 'cancel':
44 continue
45-
46+
47 if item['picking_type'] == 'in':#this is a returned picking
48 tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0 # Deducting the return picking qty
49 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
50@@ -118,7 +118,7 @@
51 tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
52 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
53 tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
54-
55+
56 for order in self.browse(cr, uid, ids, context=context):
57 if order.shipped:
58 res[order.id] = 100.0
59@@ -710,7 +710,7 @@
60 'note': line.notes,
61 'company_id': order.company_id.id,
62 })
63-
64+
65 if line.product_id:
66 proc_id = self.pool.get('procurement.order').create(cr, uid, {
67 'name': line.name,
68@@ -1010,6 +1010,53 @@
69 default.update({'state': 'draft', 'move_ids': [], 'invoiced': False, 'invoice_lines': []})
70 return super(sale_order_line, self).copy_data(cr, uid, id, default, context=context)
71
72+ def product_packaging_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False,
73+ partner_id=False, packaging=False, flag=False, context=None):
74+ if not product:
75+ return {'value': {'product_packaging': False}}
76+ product_obj = self.pool.get('product.product')
77+ product_uom_obj = self.pool.get('product.uom')
78+ pack_obj = self.pool.get('product.packaging')
79+ warning = {}
80+ result = {}
81+ warning_msgs = ''
82+ if flag:
83+ res = self.product_id_change(cr, uid, ids, pricelist=pricelist,
84+ product=product, qty=qty, uom=uom, partner_id=partner_id,
85+ packaging=packaging, flag=False, context=context)
86+ warning_msgs = res.get('warning') and res['warning']['message']
87+
88+ products = product_obj.browse(cr, uid, product, context=context)
89+ if not products.packaging:
90+ packaging = result['product_packaging'] = False
91+ elif not packaging and products.packaging and not flag:
92+ packaging = products.packaging[0].id
93+ result['product_packaging'] = packaging
94+
95+ if packaging:
96+ default_uom = products.uom_id and products.uom_id.id
97+ pack = pack_obj.browse(cr, uid, packaging, context=context)
98+ q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
99+# qty = qty - qty % q + q
100+ if qty and (q and not (qty % q) == 0):
101+ ean = pack.ean or _('(n/a)')
102+ qty_pack = pack.qty
103+ type_ul = pack.ul
104+ if not warning_msgs:
105+ warn_msg = _("You selected a quantity of %d Units.\n"
106+ "But it's not compatible with the selected packaging.\n"
107+ "Here is a proposition of quantities according to the packaging:\n"
108+ "EAN: %s Quantity: %s Type of ul: %s") % \
109+ (qty, ean, qty_pack, type_ul.name)
110+ warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
111+ warning = {
112+ 'title': _('Configuration Error !'),
113+ 'message': warning_msgs
114+ }
115+ result['product_uom_qty'] = qty
116+
117+ return {'value': result, 'warning': warning}
118+
119 def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
120 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
121 lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
122@@ -1018,7 +1065,6 @@
123 if not partner_id:
124 raise osv.except_osv(_('No Customer Defined !'), _('You have to select a customer in the sales form !\nPlease set one customer before choosing a product.'))
125 warning = {}
126- warning_msgs = ''
127 product_uom_obj = self.pool.get('product.uom')
128 partner_obj = self.pool.get('res.partner')
129 product_obj = self.pool.get('product.product')
130@@ -1033,28 +1079,10 @@
131 if not date_order:
132 date_order = time.strftime('%Y-%m-%d')
133
134- result = {}
135+ res = self.product_packaging_change(cr, uid, ids, pricelist, product, qty, uom, partner_id, packaging, context=context)
136+ result = res.get('value', {})
137+ warning_msgs = res.get('warning') and res['warning']['message'] or ''
138 product_obj = product_obj.browse(cr, uid, product, context=context)
139- if not packaging and product_obj.packaging:
140- packaging = product_obj.packaging[0].id
141- result['product_packaging'] = packaging
142-
143- if packaging:
144- default_uom = product_obj.uom_id and product_obj.uom_id.id
145- pack = self.pool.get('product.packaging').browse(cr, uid, packaging, context=context)
146- q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
147-# qty = qty - qty % q + q
148- if qty and (q and not (qty % q) == 0):
149- ean = pack.ean or _('(n/a)')
150- qty_pack = pack.qty
151- type_ul = pack.ul
152- warn_msg = _("You selected a quantity of %d Units.\n"
153- "But it's not compatible with the selected packaging.\n"
154- "Here is a proposition of quantities according to the packaging:\n"
155- "EAN: %s Quantity: %s Type of ul: %s") % \
156- (qty, ean, qty_pack, type_ul.name)
157- warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
158- result['product_uom_qty'] = qty
159
160 uom2 = False
161 if uom:
162@@ -1120,7 +1148,7 @@
163 max(0,product_obj.qty_available), product_obj.uom_id.name)
164 warning_msgs += _("Not enough stock ! : ") + warn_msg + "\n\n"
165 # get unit price
166-
167+
168 if not pricelist:
169 warn_msg = _('You have to select a pricelist or a customer in the sales form !\n'
170 'Please set one before choosing a product.')
171@@ -1141,7 +1169,7 @@
172 if warning_msgs:
173 warning = {
174 'title': _('Configuration Error !'),
175- 'message' : warning_msgs
176+ 'message' : warning_msgs
177 }
178 return {'value': result, 'domain': domain, 'warning': warning}
179
180@@ -1221,7 +1249,7 @@
181 menu_name = 'menu_invoicing_sales_order_lines'
182 data_id = data_obj.name_search(cr, uid, menu_name)
183 menu_id = data_obj.browse(cr,uid,data_id[0][0]).res_id
184- menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_ids[0]),(4,group_ids[1])]})
185+ menu_obj.write(cr, uid, menu_id, {'groups_id':[(4,group_ids[0]),(4,group_ids[1])]})
186
187 if wizard.deli_orders:
188 menu_name = 'menu_action_picking_list_to_invoice'
189@@ -1237,7 +1265,7 @@
190 module_name.append('account_analytic_analysis')
191
192 if wizard.charge_delivery:
193- module_name.append('delivery')
194+ module_name.append('delivery')
195
196 if wizard.time_unit:
197 product_obj = self.pool.get('product.product')
198@@ -1260,7 +1288,7 @@
199 if need_install:
200 pooler.restart_pool(cr.dbname, update_module=True)[1]
201
202- ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
203+ ir_values_obj.set(cr, uid, 'default', False, 'order_policy', ['sale.order'], wizard.order_policy)
204
205 sale_config_picking_policy()
206
207
208=== modified file 'sale/sale_view.xml'
209--- sale/sale_view.xml 2011-09-09 10:15:04 +0000
210+++ sale/sale_view.xml 2011-09-12 09:31:11 +0000
211@@ -4,7 +4,7 @@
212
213 <menuitem id="base.menu_sales" name="Sales" parent="base.menu_base_partner" sequence="1"/>
214
215- <menuitem id="base.menu_product" name="Products" parent="base.menu_base_partner" sequence="9"/>
216+ <menuitem id="base.menu_product" name="Products" parent="base.menu_base_partner" sequence="9"/>
217
218 <record id="view_shop_form" model="ir.ui.view">
219 <field name="name">sale.shop</field>
220@@ -124,8 +124,7 @@
221 <field name="product_uom" on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/>
222 <field groups="product.group_uos" name="product_uos_qty"/>
223 <field groups="product.group_uos" name="product_uos"/>
224- <field name="product_packaging" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, product_packaging, parent.fiscal_position, False, context)" domain="[('product_id','=',product_id)]" groups="base.group_extended"/>
225-
226+ <field name="product_packaging" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" on_change="product_packaging_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, parent.partner_id, product_packaging, True, context)" domain="[('product_id','=',product_id)]" groups="base.group_extended"/>
227 <field colspan="4" name="name"/>
228 <field name="price_unit"/>
229 <field name="discount"/>
230
231=== modified file 'sale_layout/sale_layout_view.xml'
232--- sale_layout/sale_layout_view.xml 2011-07-01 15:13:48 +0000
233+++ sale_layout/sale_layout_view.xml 2011-09-12 09:31:11 +0000
234@@ -38,7 +38,7 @@
235 name="product_packaging"
236 attrs="{'readonly':[('layout_type','!=','article')]}"
237 context="{'partner_id':parent.partner_id,'quantity':product_uom_qty,'pricelist':parent.pricelist_id,'shop':parent.shop_id,'uom':product_uom}"
238- on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, product_packaging, parent.fiscal_position, False, context)"
239+ on_change="product_packaging_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, parent.partner_id, product_packaging, True, context)"
240 domain="[('product_id','=',product_id)]"
241 groups="base.group_extended"/>
242 <separator colspan="4" string="Manual Description" />
243
244=== modified file 'warning/warning.py'
245--- warning/warning.py 2011-02-24 16:35:00 +0000
246+++ warning/warning.py 2011-09-12 09:31:11 +0000
247@@ -197,7 +197,7 @@
248 def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
249 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
250 lang=False, update_tax=True, date_order=False, packaging=False,
251- fiscal_position=False, flag=False):
252+ fiscal_position=False, flag=False, context=None):
253 warning = {}
254 if not product:
255 return {'value': {'th_weight' : 0, 'product_packaging': False,
256@@ -218,7 +218,7 @@
257
258 result = super(sale_order_line, self).product_id_change( cr, uid, ids, pricelist, product, qty,
259 uom, qty_uos, uos, name, partner_id,
260- lang, update_tax, date_order, packaging, fiscal_position, flag)
261+ lang, update_tax, date_order, packaging, fiscal_position, flag, context=context)
262
263 if result.get('warning',False):
264 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']

Subscribers

People subscribed via source and target branches

to all changes: