Ujjvala Collins (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-bug-795487-uco into
lp:openobject-addons.
Requested reviews:
Ujjvala Collins (OpenERP) (uco-openerp)
Mustufa Rangwala (Open ERP) (mra-tinyerp)
qdp (OpenERP) (qdp)
Related bugs:
Bug #795487 in OpenERP Addons: "can't unselect/make empty packaging field in
the sale order line"
https://bugs.launchpad.net/openobject-addons/+bug/795487
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-795487-uco/+merge/65440
[FIX] sale:
----------------
* Solved problem of packaging field not being empty on sale order line.
(lp:795487)
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-795487-uco/+merge/65440
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-bug-795487-uco.
=== modified file 'sale/sale.py'
--- sale/sale.py 2011-07-01 23:41:24 +0000
+++ sale/sale.py 2011-07-05 13:12:49 +0000
@@ -1010,14 +1010,61 @@
default = {}
default.update({'state': 'draft', 'move_ids': [], 'invoiced': False, 'invoice_lines': []})
return super(sale_order_line, self).copy_data(cr, uid, id, default, context=context)
+
+ def product_packaging_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False,
+ partner_id=False, packaging=False, flag=False, context=None):
+ product_obj = self.pool.get('product.product')
+ product_uom_obj = self.pool.get('product.uom')
+ pack_obj = self.pool.get('product.packaging')
+ warning = {}
+ result = {}
+ warning_msgs = ''
+ if not product:
+ return {'value': {'product_packaging': False}}
+
+ if flag:
+ res = self.product_id_change(cr, uid, ids, pricelist=pricelist,
+ product=product, qty=qty, uom=uom, partner_id=partner_id,
+ packaging=packaging, flag=False)
+ warning_msgs = res.get('warning') and res['warning']['message']
+
+ products = product_obj.browse(cr, uid, product, context=context)
+ if not products.packaging:
+ packaging = result['product_packaging'] = False
+ elif not packaging and products.packaging and not flag:
+ packaging = products.packaging[0].id
+ result['product_packaging'] = packaging
+
+ if packaging:
+ default_uom = products.uom_id and products.uom_id.id
+ pack = pack_obj.browse(cr, uid, packaging, context=context)
+ q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
+# qty = qty - qty % q + q
+ if qty and (q and not (qty % q) == 0):
+ ean = pack.ean or _('(n/a)')
+ qty_pack = pack.qty
+ type_ul = pack.ul
+ if not warning_msgs:
+ warn_msg = _("You selected a quantity of %d Units.\n"
+ "But it's not compatible with the selected packaging.\n"
+ "Here is a proposition of quantities according to the packaging:\n"
+ "EAN: %s Quantity: %s Type of ul: %s") % \
+ (qty, ean, qty_pack, type_ul.name)
+ warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
+ warning = {
+ 'title': _('Configuration Error !'),
+ 'message': warning_msgs
+ }
+ result['product_uom_qty'] = qty
+
+ return {'value': result, 'warning': warning}
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
- if not partner_id:
+ if not partner_id:
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.'))
warning = {}
- warning_msgs = ''
product_uom_obj = self.pool.get('product.uom')
partner_obj = self.pool.get('res.partner')
product_obj = self.pool.get('product.product')
@@ -1032,28 +1079,10 @@
if not date_order:
date_order = time.strftime('%Y-%m-%d')
- result = {}
+ res = self.product_packaging_change(cr, uid, ids, pricelist, product, qty, uom, partner_id, packaging)
+ result = res.get('value', {})
+ warning_msgs = res.get('warning') and res['warning']['message'] or ''
product_obj = product_obj.browse(cr, uid, product, context=context)
- if not packaging and product_obj.packaging:
- packaging = product_obj.packaging[0].id
- result['product_packaging'] = packaging
-
- if packaging:
- default_uom = product_obj.uom_id and product_obj.uom_id.id
- pack = self.pool.get('product.packaging').browse(cr, uid, packaging, context=context)
- q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
-# qty = qty - qty % q + q
- if qty and (q and not (qty % q) == 0):
- ean = pack.ean or _('(n/a)')
- qty_pack = pack.qty
- type_ul = pack.ul
- warn_msg = _("You selected a quantity of %d Units.\n"
- "But it's not compatible with the selected packaging.\n"
- "Here is a proposition of quantities according to the packaging:\n"
- "EAN: %s Quantity: %s Type of ul: %s") % \
- (qty, ean, qty_pack, type_ul.name)
- warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
- result['product_uom_qty'] = qty
uom2 = False
if uom:
=== modified file 'sale/sale_view.xml'
--- sale/sale_view.xml 2011-06-15 13:48:31 +0000
+++ sale/sale_view.xml 2011-07-05 13:12:49 +0000
@@ -142,7 +142,7 @@
<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, 'lang' in context and context['lang'], False, parent.date_order, product_packaging, parent.fiscal_position, False)"
+ on_change="product_packaging_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, parent.partner_id, product_packaging, True)"
domain="[('product_id','=',product_id)]"
groups="base.group_extended"/>
=== modified file 'sale_layout/sale_layout_view.xml'
--- sale_layout/sale_layout_view.xml 2011-06-15 13:48:31 +0000
+++ sale_layout/sale_layout_view.xml 2011-07-05 13:12:49 +0000
@@ -38,7 +38,7 @@
name="product_packaging"
attrs="{'readonly':[('layout_type','!=','article')]}"
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, 'lang' in context and context['lang'], False, parent.date_order, product_packaging, parent.fiscal_position)"
+ on_change="product_packaging_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, parent.partner_id, product_packaging, True)"
domain="[('product_id','=',product_id)]"
groups="base.group_extended"/>
<separator colspan="4" string="Manual Description" />
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp