[MERGE]Merged with Trunk-dev-addons2

bzr revid: ron@tinyerp.com-20101223045155-iz1x92tlvy9ht7w2
This commit is contained in:
ron@tinyerp.com
2010-12-23 10:21:55 +05:30
14 changed files with 118 additions and 101 deletions
@@ -193,16 +193,17 @@ class report_creator(osv.osv):
if context is None:
context = {}
data = context.get('report_id', False)
res = super(report_creator, self).read(cr, user, ids, fields, context, load)
if (not context) or 'report_id' not in context:
return super(report_creator, self).read(cr, user, ids, fields, context, load)
return res
ctx = context or {}
wp = ''
if data:
for data in res:
if not data.get('sql_query'):
return res
if self.model_set_id:
wp = [self._id_get(cr, user, data, context) + (' in (%s)' % (','.join(map(lambda x: "'" + str(x) + "'", ids))))]
report = self._sql_query_get(cr, user, [data], 'sql_query', None, ctx, where_plus = wp)
sql_query = report[data]
cr.execute(sql_query)
cr.execute(data['sql_query'])
res = cr.dictfetchall()
fields_get = self.fields_get(cr, user, None, context)
for r in res:
@@ -216,7 +217,7 @@ class report_creator(osv.osv):
related_name = self.pool.get(field_dict.get('relation')).name_get(cr, user, [r[k]], context)[0]
r[k] = related_name
return res
return res
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
"""
@@ -253,9 +254,8 @@ class report_creator(osv.osv):
newargs += [("count(*) " + a[1] +" " + str(a[2]))]
ctx = context or {}
ctx['getid'] = True
report = self._sql_query_get(cr, user, [context_id], 'sql_query', None, ctx, where_plus = newargs, limit=limit, offset=offset)
query = report[context_id]
cr.execute(query, newargs2)
sql_query = report.sql_query
cr.execute(sql_query, newargs2)
result = cr.fetchall()
return map(lambda x: x[0], result)
+1 -6
View File
@@ -665,8 +665,6 @@ class mrp_production(osv.osv):
stock_mov_obj = self.pool.get('stock.move')
production = self.browse(cr, uid, production_id, context=context)
final_product_todo = []
produced_qty = 0
if production_mode == 'consume_produce':
produced_qty = production_qty
@@ -706,10 +704,7 @@ class mrp_production(osv.osv):
stock_mov_obj.action_consume(cr, uid, [raw_product.id], consumed_qty, production.location_src_id.id, context=context)
if production_mode == 'consume_produce':
# To produce remaining qty of final product
vals = {'state':'confirmed'}
final_product_todo = [x.id for x in production.move_created_ids]
stock_mov_obj.write(cr, uid, final_product_todo, vals)
produced_products = {}
for produced_product in production.move_created_ids2:
if produced_product.scrapped:
+10 -7
View File
@@ -600,7 +600,7 @@
<field name="state" invisible="1"/>
<button name="%(stock.move_consume)d"
string="Consume Products" type="action"
icon="gtk-go-forward" context="{'consume': True }"
icon="gtk-go-forward" context="{'consume': True}"
states="draft,waiting,confirmed,assigned" />
<button
name="%(stock.track_line)d"
@@ -730,12 +730,15 @@
<field name="arch" type="xml">
<search string="Search Production">
<group col='9' colspan='4'>
<filter icon="terp-camera_test" string="Ready"
<filter icon="terp-gtk-media-pause" string="Pending" name="pending"
domain="[('state','=','confirmed')]"
help="Manufacturing Orders which are waiting for raw materials."/>
<filter icon="terp-check" string="In Production" name="inprogress"
domain="[('state','=','in_production')]"
help="Manufacturing Orders which are currently in production."/>
<filter icon="terp-camera_test" string="Ready" name="ready"
domain="[('state','=','ready')]"
help="Non confirmed manufacturing orders"/>
<filter icon="terp-check" string="Current" name="current"
domain="[('state','in',('confirmed','ready','exception','in_production'))]"
help="Manufacturing Orders which are waiting for raw materials, confirmed, ready to start or currently in production."/>
help="Manufacturing Orders which are ready to start production."/>
<separator orientation="vertical"/>
<filter icon="terp-gnome-cpu-frequency-applet+" string="Late"
domain="['&amp;', ('date_planned::date','&lt;', current_date), ('state', 'in', ('draft', 'confirmed', 'ready'))]"
@@ -767,7 +770,7 @@
<field name="view_mode">tree,form,calendar,graph,gantt</field>
<field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_mrp_production_filter"/>
<field name="context">{'search_default_current':1}</field>
<field name="context">{'search_default_ready':1}</field>
<field name="help">Manufacturing Orders are usually proposed automatically by OpenERP based on the bill of materials and the procurement rules, but you can also create manufacturing orders manually. OpenERP will handle the consumation of the raw materials (stock decrease) and the production of the finished products (stock increase) when the order is processed.</field>
</record>
<menuitem action="mrp_production_action" id="menu_mrp_production_action" parent="menu_mrp_manufacturing" groups="mrp.group_mrp_user,mrp.group_mrp_manager" sequence="1"/>
+7
View File
@@ -140,6 +140,13 @@ class StockMove(osv.osv):
res.append(new_move)
return {}
def trigger_move_state(self, cr, uid, move, state, context=None):
new_moves = super(StockMove, self).trigger_move_state(cr, uid, move, state, context=context)
if state == 'confirm':
new_moves =[x.id for x in new_moves]
self.write(cr, uid, new_moves, {'production_id': False}, context=context)
return new_moves
StockMove()
+3 -3
View File
@@ -523,9 +523,9 @@ class product_product(osv.osv):
if sellers:
for s in sellers:
mydict = {
'id': product.id,
'name': s.product_name or product.name,
'default_code': s.product_code or product.default_code,
'id': product.id,
'name': s.product_name or product.name,
'default_code': s.product_code or product.default_code,
'variants': product.variants
}
result.append(_name_get(mydict))
+4 -1
View File
@@ -99,7 +99,10 @@ class purchase_report(osv.osv):
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*u.factor)::decimal(16,2) as price_total,
avg(100.0 * (l.price_unit*l.product_qty*u.factor) / (t.standard_price*l.product_qty*u.factor))::decimal(16,2) as negociation,
avg(case when t.standard_price <= 0 then (l.price_unit*l.product_qty*u.factor)
else
(100.0 * (l.price_unit*l.product_qty*u.factor) / (t.standard_price*l.product_qty*u.factor))
end) as negociation,
sum(t.standard_price*l.product_qty*u.factor)::decimal(16,2) as price_standard,
(sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
from purchase_order s
+8 -10
View File
@@ -1,26 +1,24 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import purchase_double_validation_installer
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,22 +1,20 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -26,18 +24,17 @@
"version" : "1.1",
"category": 'Generic Modules/Sales & Purchases',
"depends" : ["base","purchase"],
"author" : "Tiny",
"author" : 'OpenERP SA',
"description": """
This module modifies purchase workflow in order to validate purchases that exceeds minimum amount set by wizard
This module modifies purchase workflow in order to validate purchases that exceeds minimum amount set by configuration wizard
""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'init_xml': [],
'update_xml': [
'purchase_double_validation_view.xml',
'purchase_double_validation_workflow.xml',
'purchase_double_validation_installer.xml', ],
'purchase_double_validation_installer.xml'
],
'demo_xml': [],
'installable': True,
'active': False,
@@ -1,24 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from osv import fields, osv
@@ -27,7 +27,7 @@ class purchase_double_validation_installer(osv.osv_memory):
_inherit = 'res.config'
_columns = {
'limit_amount': fields.integer('Limit Amount', required=True, help="Minimum amount after which validation of purchase is required"),
'limit_amount': fields.integer('Limit Amount', required=True, help="Minimum amount after which validation of purchase is required."),
}
_defaults = {
@@ -36,6 +36,8 @@ class purchase_double_validation_installer(osv.osv_memory):
def execute(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids, context=context)
if not data:
return {}
amt = data[0]['limit_amount']
data_pool = self.pool.get('ir.model.data')
transition_obj = self.pool.get('workflow.transition')
@@ -33,6 +33,7 @@
<field name="act_from" ref="act_router1"/>
<field name="act_to" ref="purchase.act_confirmed"/>
<field name="condition">True</field>
<field name="signal">waiting_confirmed</field>
</record>
<record id="trans_waiting_confirmed" model="workflow.transition">
@@ -43,4 +44,4 @@
</record>
</data>
</openerp>
</openerp>
+33 -11
View File
@@ -1762,7 +1762,8 @@ class stock_move(osv.osv):
result.setdefault(m.picking_id, [])
result[m.picking_id].append( (m, dest) )
return result
def _create_chained_picking(self, cr, uid, pick_name,picking,ptype,move, context=None):
def _create_chained_picking(self, cr, uid, pick_name, picking, ptype, move, context=None):
res_obj = self.pool.get('res.company')
picking_obj = self.pool.get('stock.picking')
pick_id= picking_obj.create(cr, uid, {
@@ -1779,6 +1780,7 @@ class stock_move(osv.osv):
'date': picking.date,
})
return pick_id
def action_confirm(self, cr, uid, ids, context=None):
""" Confirms stock move.
@return: List of ids.
@@ -1794,11 +1796,18 @@ class stock_move(osv.osv):
new_moves = []
if context is None:
context = {}
seq_obj = self.pool.get('ir.sequence')
for picking, todo in self._chain_compute(cr, uid, moves, context=context).items():
ptype = todo[0][1][5] and todo[0][1][5] or location_obj.picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0])
pick_name = picking.name or ''
if picking:
pickid = self._create_chained_picking(cr, uid, pick_name,picking,ptype,todo,context)
# name of new picking according to its type
new_pick_name = seq_obj.get(cr, uid, 'stock.picking.' + ptype)
pickid = self._create_chained_picking(cr, uid, new_pick_name, picking, ptype, todo, context=context)
# Need to check name of old picking because it always considers picking as "OUT" when created from Sale Order
old_ptype = location_obj.picking_type_get(cr, uid, picking.move_lines[0].location_id, picking.move_lines[0].location_dest_id)
if old_ptype != picking.type:
old_pick_name = seq_obj.get(cr, uid, 'stock.picking.' + old_ptype)
self.pool.get('stock.picking').write(cr, uid, picking.id, {'name': old_pick_name}, context=context)
else:
pickid = False
for move, (loc, dummy, delay, dummy, company_id, ptype) in todo:
@@ -1821,9 +1830,10 @@ class stock_move(osv.osv):
if pickid:
wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_confirm', cr)
if new_moves:
create_chained_picking(self, cr, uid, new_moves, context)
create_chained_picking(self, cr, uid, moves, context)
return []
new_moves += create_chained_picking(self, cr, uid, new_moves, context)
return new_moves
all_moves = create_chained_picking(self, cr, uid, moves, context)
return all_moves
def action_assign(self, cr, uid, ids, *args):
""" Changes state to confirmed or waiting.
@@ -2076,10 +2086,9 @@ class stock_move(osv.osv):
if move.picking_id:
picking_ids.append(move.picking_id.id)
if move.move_dest_id.id and (move.state != 'done'):
self.write(cr, uid, [move.id], {'move_history_ids': [(4, move.move_dest_id.id)]})
#cr.execute('insert into stock_move_history_ids (parent_id,child_id) values (%s,%s)', (move.id, move.move_dest_id.id))
self.write(cr, uid, [move.id], {'stock_move_history_ids': [(4, move.move_dest_id.id)]}, context=context)
if move.move_dest_id.state in ('waiting', 'confirmed'):
self.write(cr, uid, [move.move_dest_id.id], {'state': 'assigned'})
self.action_assign(cr, uid, [move.move_dest_id.id])
if move.move_dest_id.picking_id:
wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
if move.move_dest_id.auto_validate:
@@ -2265,7 +2274,18 @@ class stock_move(osv.osv):
self.write(cr, uid, [current_move], update_val)
return res
def action_consume(self, cr, uid, ids, quantity, location_id=False, context=None):
def trigger_move_state(self, cr, uid, move, state, context=None):
if isinstance(move, (int, long)):
move = [move]
res = []
if state == 'confirm':
res = self.action_confirm(cr, uid, move, context=context)
if state == 'assigned':
self.check_assign(cr, uid, move, context=context)
self.force_assign(cr, uid, move, context=context)
return res
def action_consume(self, cr, uid, ids, quantity, location_id=False, context=None):
""" Consumed product with specific quatity from specific source location
@param cr: the database cursor
@param uid: the user id
@@ -2293,12 +2313,12 @@ class stock_move(osv.osv):
quantity = move.product_qty
uos_qty = quantity / move_qty * move.product_uos_qty
state = (move.state in ('confirm', 'assign') and move.state) or 'confirm'
if quantity_rest > 0:
default_val = {
'product_qty': quantity,
'product_uos_qty': uos_qty,
'state': move.state,
'location_id': location_id or move.location_id.id,
}
if (not move.prodlot_id.id) and (move.product_id.track_production and location_id):
@@ -2331,6 +2351,8 @@ class stock_move(osv.osv):
for (id, name) in product_obj.name_get(cr, uid, [new_move.product_id.id]):
message = _('Product ') + " '" + name + "' "+ _("is consumed with") + " '" + str(new_move.product_qty) + "' "+ _("quantity.")
self.log(cr, uid, new_move.id, message)
self.trigger_move_state(cr, uid, res, state, context=context)
self.action_done(cr, uid, res)
return res
@@ -29,8 +29,8 @@ class stock_change_product_qty(osv.osv_memory):
_columns = {
'product_id' : fields.many2one('product.product', 'Product'),
'new_quantity': fields.float('Quantity', required=True, help='This quantity is expressed in the Default UoM of the product.'),
'prodlot_id': fields.many2one('stock.production.lot', 'Lot Number',domain="[('product_id','=',product_id)]"),
'location_id': fields.many2one('stock.location', 'Location', required=True, ondelete="cascade", domain="[('usage', '=', 'internal')]"),
'prodlot_id': fields.many2one('stock.production.lot', 'Production Lot', domain="[('product_id','=',product_id)]"),
'location_id': fields.many2one('stock.location', 'Location', required=True, domain="[('usage', '=', 'internal')]"),
}
def default_get(self, cr, uid, fields, context):
@@ -89,7 +89,7 @@ class stock_change_product_qty(osv.osv_memory):
inventry_obj.action_done(cr, uid, [inventory_id], context=context)
return {
'domain': "[('id','=',inventory_id])]",
'domain': "[('id','=', %s)]" % (inventory_id),
'name' : _('Physical Inventories'),
'view_type': 'form',
'view_mode': 'tree,form',
@@ -11,9 +11,9 @@
<newline/>
<field name="new_quantity" />
<newline/>
<field name="prodlot_id" />
<field name="product_id" invisible="1"/>
<field name="location_id" />
<field name="prodlot_id" />
<separator string="" colspan="4" />
<label string="" colspan="2"/>
<group col="2" colspan="2">
@@ -30,7 +30,6 @@
<field name="res_model">stock.change.product.qty</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="context">{'default_product_id': active_id}</field>
<field name="view_id" ref="view_change_product_quantity"/>
<field name="target">new</field>
</record>
@@ -60,60 +60,50 @@ class stock_period_createlines(osv.osv_memory):
period_obj = self.pool.get('stock.period')
lines = []
for p in self.browse(cr, uid, ids, context=context):
dt = p.date_start
dt_s = p.date_stop
dt_stp = datetime.strptime(p.date_stop, '%Y-%m-%d')
ds = datetime.strptime(p.date_start, '%Y-%m-%d')
while ds.strftime('%Y-%m-%d') <= p.date_stop:
while ds <= dt_stp:
if name =='Daily':
de = ds + relativedelta(days=(interval + 1), seconds =-1)
new_name = de.strftime('%Y-%m-%d')
new_id = period_obj.create(cr, uid, {
'name': new_name,
'date_start': ds.strftime('%Y-%m-%d'),
'name': de.strftime('%Y-%m-%d'),
'date_start': ds.strftime('%Y-%m-%d %H:%M:%S'),
'date_stop': de.strftime('%Y-%m-%d %H:%M:%S'),
})
ds = ds + relativedelta(days=(interval + 1))
if name =="Weekly":
de = ds + relativedelta(days=(interval + 1), seconds =-1)
if dt_stp < de:
de = dt_stp + relativedelta(days=1,seconds =-1)
de = dt_stp + relativedelta(days=1, seconds =-1)
else:
de = ds + relativedelta(days=(interval + 1), seconds =-1)
start_week = ds.strftime('%W')
start_year = ds.strftime('%Y')
end_week = de.strftime('%W')
end_year = de.strftime('%Y')
if start_year <> end_year:
if end_week == '00':
new_name = "Week " + start_week +"-" + start_year
else:
new_name = "Week " + start_week +", " + start_year +" - Week " +end_week +", " + end_year
elif start_week == end_week:
new_name = "Week " + start_week +"-" +start_year
else:
new_name = "Week " + start_week +"-" + end_week+", " + start_year
new_name = ds.strftime('Week %W-%Y')
if ds.strftime('%Y') != de.strftime('%Y'):
new_name = ds.strftime('Week %W-%Y') + ', ' + de.strftime('Week %W-%Y')
new_id = period_obj.create(cr, uid, {
'name': new_name,
'date_start': ds.strftime('%Y-%m-%d'),
'date_start': ds.strftime('%Y-%m-%d %H:%M:%S'),
'date_stop': de.strftime('%Y-%m-%d %H:%M:%S'),
})
ds = ds + relativedelta(days=(interval + 1))
if name == "Monthly":
de = ds + relativedelta(months=interval, seconds=-1)
if dt_stp < de:
de = dt_stp + relativedelta(days=1,seconds =-1)
de = dt_stp + relativedelta(days=1, seconds =-1)
else:
de = ds + relativedelta(months=interval, seconds=-1)
new_name = ds.strftime('%Y/%m')
if ds.strftime('%m') != de.strftime('%m'):
new_name = ds.strftime('%Y/%m') + '-' + de.strftime('%Y/%m')
new_id =period_obj.create(cr, uid, {
'name': new_name,
'date_start': ds.strftime('%Y-%m-%d'),
'name': new_name,
'date_start': ds.strftime('%Y-%m-%d %H:%M:%S'),
'date_stop': de.strftime('%Y-%m-%d %H:%M:%S'),
})
ds = ds + relativedelta(months=interval)
lines.append(new_id)
return {
'domain': "[('id','in', ["+','.join(map(str, lines))+"])]",
'view_type': 'form',