'weight_uom_id': lambda self,cr,uid,c: self._get_default_uom(cr,uid,c)
}
-# Redefinition of the new fields in order to update the model stock.picking.out in the orm
-# FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as
-# the bug is fixed
-
-# TODO in trunk: Remove the duplication below using a mixin class!
-
-class stock_picking_out(osv.osv):
- _inherit = 'stock.picking.out'
-
- def _cal_weight(self, cr, uid, ids, name, args, context=None):
- return self.pool.get('stock.picking')._cal_weight(cr, uid, ids, name, args, context=context)
-
-
- def _get_picking_line(self, cr, uid, ids, context=None):
- return self.pool.get('stock.picking')._get_picking_line(cr, uid, ids, context=context)
-
- _columns = {
- 'carrier_id':fields.many2one("delivery.carrier","Carrier"),
- 'volume': fields.float('Volume'),
- 'weight': fields.function(_cal_weight, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
- store={
- 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
- 'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
- }),
- 'weight_net': fields.function(_cal_weight, type='float', string='Net Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
- store={
- 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
- 'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
- }),
- 'carrier_tracking_ref': fields.char('Carrier Tracking Ref', size=32),
- 'number_of_packages': fields.integer('Number of Packages'),
- 'weight_uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True,readonly="1",help="Unit of measurement for Weight",),
- }
-
-class stock_picking_in(osv.osv):
- _inherit = 'stock.picking.in'
-
- def _cal_weight(self, cr, uid, ids, name, args, context=None):
- return self.pool.get('stock.picking')._cal_weight(cr, uid, ids, name, args, context=context)
-
- def _get_picking_line(self, cr, uid, ids, context=None):
- return self.pool.get('stock.picking')._get_picking_line(cr, uid, ids, context=context)
-
- _columns = {
- 'carrier_id':fields.many2one("delivery.carrier","Carrier"),
- 'volume': fields.float('Volume'),
- 'weight': fields.function(_cal_weight, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
- store={
- 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
- 'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
- }),
- 'weight_net': fields.function(_cal_weight, type='float', string='Net Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
- store={
- 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
- 'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
- }),
- 'carrier_tracking_ref': fields.char('Carrier Tracking Ref', size=32),
- 'number_of_packages': fields.integer('Number of Packages'),
- 'weight_uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True,readonly="1",help="Unit of measurement for Weight",),
- }
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
--
@return: True
"""
stock_picking_obj = self.pool.get('stock.picking')
- wf_service = netsvc.LocalService("workflow")
for order in self.browse(cr, uid, ids, context=context):
- stock_picking_obj.signal_button_cancel(cr, uid, [order.picking_id.id])
+ stock_picking_obj.action_cancel(cr, uid, [order.picking_id.id])
if stock_picking_obj.browse(cr, uid, order.picking_id.id, context=context).state <> 'cancel':
raise osv.except_osv(_('Error!'), _('Unable to cancel the picking.'))
self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
##############################################################################
from openerp.osv import fields, osv
-from openerp import workflow
+from openerp.tools.translate import _
+
+class procurement_order(osv.osv):
+ _name = "procurement.order"
+ _inherit = "procurement.order"
+ _columns = {
+ 'task_id': fields.many2one('project.task', 'Task'),
+ 'sale_line_id': fields.many2one('sale.order.line', 'Sales order line')
+ }
+
+ def _is_procurement_task(self, cr, uid, procurement, context=None):
+ return procurement.product_id.type == 'service' and procurement.product_id.auto_create_task or False
+
+ def _assign(self, cr, uid, procurement, context=None):
+ res = super(procurement_order, self)._assign(cr, uid, procurement, context=context)
+ if not res:
+ #if there isn't any specific procurement.rule defined for the product, we may want to create a task
+ if self._is_procurement_task(cr, uid, procurement, context=context):
+ return True
+ return res
+
+ def _run(self, cr, uid, procurement, context=None):
+ if self._is_procurement_task(cr, uid, procurement, context=context) and not procurement.task_id:
+ #create a task for the procurement
+ return self._create_service_task(cr, uid, procurement, context=context)
+ return super(procurement_order, self)._run(cr, uid, procurement, context=context)
+
+ def _check(self, cr, uid, procurement, context=None):
+ if self._is_procurement_task(cr, uid, procurement, context=context):
+ return procurement.task_id and procurement.task_id.stage_id.closed or False
+ return super(procurement_order, self)._check(cr, uid, procurement, context=context)
+
+ def _convert_qty_company_hours(self, cr, uid, procurement, context=None):
+ product_uom = self.pool.get('product.uom')
+ company_time_uom_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
+ if procurement.product_uom.id != company_time_uom_id.id and procurement.product_uom.category_id.id == company_time_uom_id.category_id.id:
+ planned_hours = product_uom._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, company_time_uom_id.id)
+ else:
+ planned_hours = procurement.product_qty
+ return planned_hours
+
+ def _get_project(self, cr, uid, procurement, context=None):
+ project_project = self.pool.get('project.project')
+ project = procurement.product_id.project_id
+ if not project and procurement.sale_line_id:
+ # find the project corresponding to the analytic account of the sales order
+ account = procurement.sale_line_id.order_id.project_id
+ project_ids = project_project.search(cr, uid, [('analytic_account_id', '=', account.id)])
+ projects = project_project.browse(cr, uid, project_ids, context=context)
+ project = projects and projects[0] or False
+ return project
+
+ def _create_service_task(self, cr, uid, procurement, context=None):
+ project_task = self.pool.get('project.task')
+ project = self._get_project(cr, uid, procurement, context=context)
+ planned_hours = self._convert_qty_company_hours(cr, uid, procurement, context=context)
+ task_id = project_task.create(cr, uid, {
+ 'name': '%s:%s' % (procurement.origin or '', procurement.product_id.name),
+ 'date_deadline': procurement.date_planned,
+ 'planned_hours': planned_hours,
+ 'remaining_hours': planned_hours,
+ 'partner_id': procurement.sale_line_id and procurement.sale_line_id.order_id.partner_id.id or False,
+ 'user_id': procurement.product_id.product_manager.id,
+ 'procurement_id': procurement.id,
+ 'description': procurement.name + '\n',
+ 'project_id': project and project.id or False,
+ 'company_id': procurement.company_id.id,
+ },context=context)
+ self.write(cr, uid, [procurement.id], {'task_id': task_id, 'message':_('Task created.')}, context=context)
+ self.project_task_create_note(cr, uid, [procurement.id], context=context)
+ return task_id
+
+ def project_task_create_note(self, cr, uid, ids, context=None):
+ for procurement in self.browse(cr, uid, ids, context=context):
+ body = _("Task created")
+ self.message_post(cr, uid, [procurement.id], body=body, context=context)
+ if procurement.sale_line_id and procurement.sale_line_id.order_id:
+ procurement.sale_line_id.order_id.message_post(body=body)
-
class ProjectTaskStageMrp(osv.Model):
""" Override project.task.type model to add a 'closed' boolean field allowing
to know that tasks in this stage are considered as closed. Indeed since
'invoiced':False,
'invoice_ids': [],
'picking_ids': [],
+ 'origin' : '',
+ 'partner_ref': '',
'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order'),
})
return super(purchase_order, self).copy(cr, uid, id, default, context)
extract(epoch from age(s.date_approve,s.date_order))/(24*60*60)::decimal(16,2) as delay,
extract(epoch from age(l.date_planned,s.date_order))/(24*60*60)::decimal(16,2) as delay_pass,
count(*) as nbr,
- (l.price_unit*l.product_qty)::decimal(16,2) as price_total,
+ sum(l.price_unit*l.product_qty)::decimal(16,2) as price_total,
- avg(100.0 * (l.price_unit*l.product_qty) / NULLIF(t.standard_price*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
- sum(t.standard_price*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
+ avg(100.0 * (l.price_unit*l.product_qty) / NULLIF(ip.value_float*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
+ sum(ip.value_float*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
(sum(l.product_qty*l.price_unit)/NULLIF(sum(l.product_qty/u.factor*u2.factor),0.0))::decimal(16,2) as price_average
- from purchase_order s
- left join purchase_order_line l on (s.id=l.order_id)
+ from purchase_order_line l
+ join purchase_order s on (l.order_id=s.id)
left join product_product p on (l.product_id=p.id)
left join product_template t on (p.product_tmpl_id=t.id)
+ LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',t.id) AND ip.company_id=s.company_id)
left join product_uom u on (u.id=l.product_uom)
left join product_uom u2 on (u2.id=t.uom_id)
- where l.product_id is not null
group by
s.company_id,
s.create_uid,
if len(invoice_ids) == len(ids):
#Cancel invoice(s) first before deleting them so that if any sale order is associated with them
#it will trigger the workflow to put the sale order in an 'invoice exception' state
- wf_service = netsvc.LocalService("workflow")
for id in ids:
- wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
+ workflow.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
return super(account_invoice, self).unlink(cr, uid, ids, context=context)
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+class procurement_order(osv.osv):
+ _inherit = 'procurement.order'
+ _columns = {
+ 'sale_line_id': fields.many2one('sale.order.line', string='Sale Order Line'),
+ }
+
('cancel', 'Cancelled')
], 'Order Status', readonly=True),
}
-
def init(self, cr):
tools.drop_view_if_exists(cr, 'sale_report')
+ # TODO: make parent view extensible similarly to invoice analysis and
+ # remove the duplication
cr.execute("""
create or replace view sale_report as (
select
_inherit = 'purchase.order.line'
def onchange_product_id(self,cr, uid, ids, pricelist, product, qty, uom,
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
- name=False, price_unit=False, notes=False, context=None):
+ name=False, price_unit=False, state='draft', notes=False, context=None):
warning = {}
if not product:
- return {'value': {'price_unit': 0.0, 'name':'','notes':'', 'product_uom' : False}, 'domain':{'product_uom':[]}}
+ return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom or False}, 'domain':{'product_uom':[]}}
product_obj = self.pool.get('product.product')
product_info = product_obj.browse(cr, uid, product)
title = False