class sale_order(osv.osv):
_name = "sale.order"
+ _log_create = True
_description = "Sale Order"
def copy(self, cr, uid, id, default=None, context=None):
for id in ids:
res[id] = [0.0, 0.0]
cr.execute('''SELECT
- p.sale_id,sum(m.product_qty), m.state
+ p.sale_id,sum(m.product_qty), mp.state as mp_state
FROM
stock_move m
LEFT JOIN
stock_picking p on (p.id=m.picking_id)
+ LEFT JOIN
+ mrp_procurement mp on (mp.move_id=m.id)
WHERE
- p.sale_id = ANY(%s) GROUP BY m.state, p.sale_id''',(ids,))
- for oid, nbr, state in cr.fetchall():
- if state == 'cancel':
+ p.sale_id = ANY(%s) GROUP BY mp.state, p.sale_id''',(ids,))
+ for oid, nbr, mp_state in cr.fetchall():
+ if mp_state == 'cancel':
continue
- if state == 'done':
+ if mp_state == 'done':
res[oid][0] += nbr or 0.0
res[oid][1] += nbr or 0.0
else:
'partner_id': fields.many2one('res.partner', 'Customer', readonly=True, states={'draft': [('readonly', False)]}, required=True, change_default=True, select=True),
'partner_invoice_id': fields.many2one('res.partner.address', 'Invoice Address', readonly=True, required=True, states={'draft': [('readonly', False)]}),
'partner_order_id': fields.many2one('res.partner.address', 'Ordering Contact', readonly=True, required=True, states={'draft': [('readonly', False)]}, help="The name and address of the contact who requested the order or quotation."),
- 'partner_shipping_id': fields.many2one('res.partner.address', 'Shipping Address', readonly=True, required=True, states={'draft': [('readonly', False)]}),
+ 'partner_shipping_id': fields.many2one('res.partner.address', 'Shipping Address', readonly=True, required=True, states={'draft': [('readonly', False)]}, help="Shipping address for current sale order"),
'incoterm': fields.selection(_incoterm_get, 'Incoterm', size=3),
'picking_policy': fields.selection([('direct', 'Partial Delivery'), ('one', 'Complete Delivery')],
- The 'Shipping & Manual Invoice' will create the picking order directly and wait for the user to manually click on the 'Invoice' button to generate the draft invoice.
- The 'Invoice on Order After Delivery' choice will generate the draft invoice based on sale order after all picking lists have been finished.
- The 'Invoice from the picking' choice is used to create an invoice during the picking process."""),
- 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)]}),
+ 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)]}, help="Pricelist version for current sale order"),
'project_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True, states={'draft': [('readonly', False)]}),
'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)]}),
'partner_invoice_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['invoice'])['invoice'],
'partner_order_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['contact'])['contact'],
'partner_shipping_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['delivery'])['delivery'],
- 'pricelist_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist.id,
+# 'pricelist_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist.id,
}
_order = 'name desc'
'currency_id': order.pricelist_id.currency_id.id,
'comment': order.note,
'payment_term': pay_term,
- 'fiscal_position': order.partner_id.property_account_position.id,
+ 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
'date_invoice' : context.get('date_invoice',False),
'company_id' : order.company_id.id,
}
def action_invoice_end(self, cr, uid, ids, context=None):
if context is None:
context = {}
- for order in self.browse(cr, uid, ids, context=context):
- val = {'invoiced': True}
- if order.state == 'invoice_except':
- val['state'] = 'progress'
+ for order in self.browse(cr, uid, ids, context=context):
for line in order.order_line:
- towrite = []
if line.state == 'exception':
- towrite.append(line.id)
- if towrite:
- self.pool.get('sale.order.line').write(cr, uid, towrite, {'state': 'confirmed'}, context=context)
- self.write(cr, uid, [order.id], val)
+ self.pool.get('sale.order.line').write(cr, uid, [line.id], {'state': 'confirmed'}, context=context)
+
+ if order.state == 'invoice_except':
+ self.write(cr, uid, [order.id], {'state' : 'progress'}, context=context)
return True
return True
def action_wait(self, cr, uid, ids, *args):
- event_p = self.pool.get('res.partner.event.type').check(cr, uid, 'sale_open')
- event_obj = self.pool.get('res.partner.event')
+ for (id,name) in self.name_get(cr, uid, ids):
+ message = _('Quotation ') + " '" + name + "' "+ _("converted to sale order.")
+ self.log(cr, uid, id, message)
for o in self.browse(cr, uid, ids):
- if event_p:
- event_obj.create(cr, uid, {'name': 'Sale Order: '+ o.name,\
- 'partner_id': o.partner_id.id,\
- 'date': time.strftime('%Y-%m-%d %H:%M:%S'),\
- 'user_id': (o.user_id and o.user_id.id) or uid,\
- 'partner_type': 'customer', 'probability': 1.0,\
- 'planned_revenue': o.amount_untaxed})
if (o.order_policy == 'manual'):
self.write(cr, uid, [o.id], {'state': 'manual', 'date_confirm': time.strftime('%Y-%m-%d')})
else:
return res
_name = 'sale.order.line'
- _description = 'Sale Order line'
+ _description = 'Sale Order Line'
_columns = {
'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
'name': fields.char('Description', size=256, required=True, select=True, readonly=True, states={'draft':[('readonly',False)]}),
'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft':[('readonly',False)]}),
'address_allotment_id': fields.many2one('res.partner.address', 'Allotment Partner'),
'product_uom_qty': fields.float('Quantity (UoM)', digits=(16, 2), required=True, readonly=True, states={'draft':[('readonly',False)]}),
- 'product_uom': fields.many2one('product.uom', 'Product UoM', required=True, readonly=True, states={'draft':[('readonly',False)]}),
+ 'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'product_uos_qty': fields.float('Quantity (UoS)', readonly=True, states={'draft':[('readonly',False)]}),
'product_uos': fields.many2one('product.uom', 'Product UoS'),
'product_packaging': fields.many2one('product.packaging', 'Packaging'),
'product_uos':
[('category_id', '=', uos_category_id)]}
- elif uos: # only happens if uom is False
+ elif uos and not uom: # only happens if uom is False
result['product_uom'] = product_obj.uom_id and product_obj.uom_id.id
result['product_uom_qty'] = qty_uos / product_obj.uos_coeff
result['th_weight'] = result['product_uom_qty'] * product_obj.weight
warning = {
'title': 'No Pricelist !',
'message':
- 'You have to select a pricelist in the sale form !\n'
+ 'You have to select a pricelist or a customer in the sale form !\n'
'Please set one before choosing a product.'
}
else:
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False):
res = self.product_id_change(cursor, user, ids, pricelist, product,
- qty=0, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
+ qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
partner_id=partner_id, lang=lang, update_tax=update_tax,
date_order=date_order)
if 'product_uom' in res['value']: