[MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 10016 revid:dle@openerp.com-20140425125507-njfyl1r6wn11vqwx

bzr revid: dle@openerp.com-20140425125926-5nchz1tcq4fx18jx
This commit is contained in:
Denis Ledoux 2014-04-25 14:59:26 +02:00
commit 2832d2ddc9
4 changed files with 52 additions and 32 deletions

View File

@ -20,10 +20,11 @@
############################################################################## ##############################################################################
import time import time
from datetime import datetime, timedelta from datetime import datetime
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from openerp.osv import fields, osv from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp.tools.translate import _ from openerp.tools.translate import _
class hr_timesheet_sheet(osv.osv): class hr_timesheet_sheet(osv.osv):
@ -385,18 +386,22 @@ class hr_attendance(osv.osv):
attendance_ids.extend([row[0] for row in cr.fetchall()]) attendance_ids.extend([row[0] for row in cr.fetchall()])
return attendance_ids return attendance_ids
def _get_current_sheet(self, cr, uid, employee_id, date=False, context=None):
if not date:
date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
# ending date with no time to avoid timesheet with early date_to
date_to = date[0:10]+' 00:00:00'
# limit=1 because only one sheet possible for an employee between 2 dates
sheet_ids = self.pool.get('hr_timesheet_sheet.sheet').search(cr, uid, [
('date_to', '>=', date_to), ('date_from', '<=', date),
('employee_id', '=', employee_id)
], limit=1, context=context)
return sheet_ids and sheet_ids[0] or False
def _sheet(self, cursor, user, ids, name, args, context=None): def _sheet(self, cursor, user, ids, name, args, context=None):
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
res = {}.fromkeys(ids, False) res = {}.fromkeys(ids, False)
for attendance in self.browse(cursor, user, ids, context=context): for attendance in self.browse(cursor, user, ids, context=context):
date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S') res[attendance.id] = self._get_current_sheet(cursor, user, attendance.employee_id.id, attendance.name, context=context)
sheet_ids = sheet_obj.search(cursor, user,
[('date_to', '>=', date_to), ('date_from', '<=', attendance.name),
('employee_id', '=', attendance.employee_id.id)],
context=context)
if sheet_ids:
# [0] because only one sheet possible for an employee between 2 dates
res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
return res return res
_columns = { _columns = {
@ -415,16 +420,15 @@ class hr_attendance(osv.osv):
def create(self, cr, uid, vals, context=None): def create(self, cr, uid, vals, context=None):
if context is None: if context is None:
context = {} context = {}
if 'sheet_id' in context:
ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'], context=context) sheet_id = context.get('sheet_id') or self._get_current_sheet(cr, uid, vals.get('employee_id'), vals.get('name'), context=context)
if sheet_id:
ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, sheet_id, context=context)
if ts.state not in ('draft', 'new'): if ts.state not in ('draft', 'new'):
raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet.')) raise osv.except_osv(_('Error!'), _('You can not enter an attendance in a submitted timesheet. Ask your manager to reset it before adding attendance.'))
res = super(hr_attendance,self).create(cr, uid, vals, context=context) elif ts.date_from > vals.get('name') or ts.date_to < vals.get('name'):
if 'sheet_id' in context: raise osv.except_osv(_('User Error!'), _('You can not enter an attendance date outside the current timesheet dates.'))
if context['sheet_id'] != self.browse(cr, uid, res, context=context).sheet_id.id: return super(hr_attendance,self).create(cr, uid, vals, context=context)
raise osv.except_osv(_('User Error!'), _('You cannot enter an attendance ' \
'date outside the current timesheet dates.'))
return res
def unlink(self, cr, uid, ids, *args, **kwargs): def unlink(self, cr, uid, ids, *args, **kwargs):
if isinstance(ids, (int, long)): if isinstance(ids, (int, long)):

View File

@ -805,9 +805,17 @@ class product_product(osv.osv):
price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id
res = {} res = {}
# standard_price field can only be seen by users in base.group_user
# Thus, in order to compute the sale price from the cost price for users not in this group
# We fetch the standard price as the superuser
for product in products:
if ptype != 'standard_price':
res[product.id] = product[ptype] or 0.0
else:
res[product.id] = self.read(cr, SUPERUSER_ID, product.id, [ptype], context=context)[ptype] or 0.0
product_uom_obj = self.pool.get('product.uom') product_uom_obj = self.pool.get('product.uom')
for product in products: for product in products:
res[product.id] = product[ptype] or 0.0
if ptype == 'list_price': if ptype == 'list_price':
res[product.id] = (res[product.id] * (product.price_margin or 1.0)) + \ res[product.id] = (res[product.id] * (product.price_margin or 1.0)) + \
product.price_extra product.price_extra

View File

@ -357,7 +357,6 @@ class sale_order(osv.osv):
} }
def ship_recreate(self, cr, uid, order, line, move_id, proc_id): def ship_recreate(self, cr, uid, order, line, move_id, proc_id):
# FIXME: deals with potentially cancelled shipments, seems broken (specially if shipment has production lot)
""" """
Define ship_recreate for process after shipping exception Define ship_recreate for process after shipping exception
param order: sales order to which the order lines belong param order: sales order to which the order lines belong
@ -366,16 +365,25 @@ class sale_order(osv.osv):
param proc_id: the ID of procurement param proc_id: the ID of procurement
""" """
move_obj = self.pool.get('stock.move') move_obj = self.pool.get('stock.move')
if order.state == 'shipping_except': proc_obj = self.pool.get('procurement.order')
for pick in order.picking_ids: if move_id and order.state == 'shipping_except':
for move in pick.move_lines: current_move = move_obj.browse(cr, uid, move_id)
if move.state == 'cancel': moves = []
mov_ids = move_obj.search(cr, uid, [('state', '=', 'cancel'),('sale_line_id', '=', line.id),('picking_id', '=', pick.id)]) for picking in order.picking_ids:
if mov_ids: if picking.id != current_move.picking_id.id and picking.state != 'cancel':
for mov in move_obj.browse(cr, uid, mov_ids): moves.extend(move for move in picking.move_lines if move.state != 'cancel' and move.sale_line_id.id == line.id)
# FIXME: the following seems broken: what if move_id doesn't exist? What if there are several mov_ids? Shouldn't that be a sum? if moves:
move_obj.write(cr, uid, [move_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty}) product_qty = current_move.product_qty
self.pool.get('procurement.order').write(cr, uid, [proc_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty}) product_uos_qty = current_move.product_uos_qty
for move in moves:
product_qty -= move.product_qty
product_uos_qty -= move.product_uos_qty
if product_qty > 0 or product_uos_qty > 0:
move_obj.write(cr, uid, [move_id], {'product_qty': product_qty, 'product_uos_qty': product_uos_qty})
proc_obj.write(cr, uid, [proc_id], {'product_qty': product_qty, 'product_uos_qty': product_uos_qty})
else:
current_move.unlink()
proc_obj.unlink(cr, uid, [proc_id])
return True return True
def _get_date_planned(self, cr, uid, order, line, start_date, context=None): def _get_date_planned(self, cr, uid, order, line, start_date, context=None):

View File

@ -1271,7 +1271,7 @@
<field name="date" attrs="{'invisible': [('state', '!=', 'done')]}"/> <field name="date" attrs="{'invisible': [('state', '!=', 'done')]}"/>
</group> </group>
<group string="Traceability" <group string="Traceability"
groups="stock.group_tracking_lot"> groups="stock.group_tracking_lot,stock.group_production_lot">
<label for="tracking_id" groups="stock.group_tracking_lot"/> <label for="tracking_id" groups="stock.group_tracking_lot"/>
<div groups="stock.group_tracking_lot"> <div groups="stock.group_tracking_lot">
<field name="tracking_id" class="oe_inline"/> <field name="tracking_id" class="oe_inline"/>