[MERGE] lp: 809491,795487
bzr revid: qdp-launchpad@openerp.com-20111019145645-09ql24jn120uw11f
This commit is contained in:
@@ -40,7 +40,8 @@ class sale_order_line(osv.osv):
|
||||
|
||||
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):
|
||||
lang=False, update_tax=True, date_order=False, packaging=False,
|
||||
fiscal_position=False, flag=False, context=None):
|
||||
|
||||
def get_real_price(res_dict, product_id, qty, uom, pricelist):
|
||||
item_obj = self.pool.get('product.pricelist.item')
|
||||
@@ -59,7 +60,7 @@ class sale_order_line(osv.osv):
|
||||
product_tmpl_id = product.product_tmpl_id.id
|
||||
|
||||
product_read = template_obj.read(cr, uid, product_tmpl_id, [field_name], context)
|
||||
|
||||
|
||||
factor = 1.0
|
||||
if uom and uom != product.uom_id.id:
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
@@ -70,7 +71,7 @@ class sale_order_line(osv.osv):
|
||||
|
||||
res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
|
||||
uom, qty_uos, uos, name, partner_id,
|
||||
lang, update_tax,date_order,fiscal_position=fiscal_position,flag=flag)
|
||||
lang, update_tax, date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)
|
||||
|
||||
context = {'lang': lang, 'partner_id': partner_id}
|
||||
result=res['value']
|
||||
|
||||
+53
-25
@@ -106,7 +106,7 @@ class sale_order(osv.osv):
|
||||
procurement_order mp on (mp.move_id=m.id)
|
||||
WHERE
|
||||
p.sale_id IN %s GROUP BY m.state, mp.state, p.sale_id, p.type''', (tuple(ids),))
|
||||
|
||||
|
||||
for item in cr.dictfetchall():
|
||||
if item['move_state'] == 'cancel':
|
||||
continue
|
||||
@@ -1073,6 +1073,53 @@ class sale_order_line(osv.osv):
|
||||
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):
|
||||
if not product:
|
||||
return {'value': {'product_packaging': False}}
|
||||
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 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, context=context)
|
||||
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, context=None):
|
||||
@@ -1081,7 +1128,6 @@ class sale_order_line(osv.osv):
|
||||
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')
|
||||
@@ -1097,28 +1143,10 @@ class sale_order_line(osv.osv):
|
||||
if not date_order:
|
||||
date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
result = {}
|
||||
res = self.product_packaging_change(cr, uid, ids, pricelist, product, qty, uom, partner_id, packaging, context=context)
|
||||
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:
|
||||
@@ -1184,7 +1212,7 @@ class sale_order_line(osv.osv):
|
||||
max(0,product_obj.qty_available), product_obj.uom_id.name)
|
||||
warning_msgs += _("Not enough stock ! : ") + warn_msg + "\n\n"
|
||||
# get unit price
|
||||
|
||||
|
||||
if not pricelist:
|
||||
warn_msg = _('You have to select a pricelist or a customer in the sales form !\n'
|
||||
'Please set one before choosing a product.')
|
||||
@@ -1205,7 +1233,7 @@ class sale_order_line(osv.osv):
|
||||
if warning_msgs:
|
||||
warning = {
|
||||
'title': _('Configuration Error !'),
|
||||
'message' : warning_msgs
|
||||
'message' : warning_msgs
|
||||
}
|
||||
return {'value': result, 'domain': domain, 'warning': warning}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<menuitem id="base.menu_sales" name="Sales" parent="base.menu_base_partner" sequence="1"/>
|
||||
|
||||
<menuitem id="base.menu_product" name="Products" parent="base.menu_base_partner" sequence="9"/>
|
||||
<menuitem id="base.menu_product" name="Products" parent="base.menu_base_partner" sequence="9"/>
|
||||
|
||||
<record id="view_shop_form" model="ir.ui.view">
|
||||
<field name="name">sale.shop</field>
|
||||
@@ -127,8 +127,7 @@
|
||||
<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)"/>
|
||||
<field groups="product.group_uos" name="product_uos_qty"/>
|
||||
<field groups="product.group_uos" name="product_uos"/>
|
||||
<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"/>
|
||||
|
||||
<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"/>
|
||||
<field colspan="4" name="name"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount"/>
|
||||
|
||||
@@ -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, False, False, parent.date_order, product_packaging, parent.fiscal_position, False, context)"
|
||||
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"/>
|
||||
<separator colspan="4" string="Manual Description" />
|
||||
|
||||
@@ -218,7 +218,7 @@ class sale_order_line(osv.osv):
|
||||
|
||||
result = super(sale_order_line, self).product_id_change( cr, uid, ids, pricelist, product, qty,
|
||||
uom, qty_uos, uos, name, partner_id,
|
||||
lang, update_tax, date_order, packaging, fiscal_position, flag)
|
||||
lang, update_tax, date_order, packaging, fiscal_position, flag, context=context)
|
||||
|
||||
if result.get('warning',False):
|
||||
warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
|
||||
|
||||
Reference in New Issue
Block a user