[MERGE]
bzr revid: mra@mra-laptop-20100616111209-b41bw9pc1iot0lae
This commit is contained in:
@@ -30,7 +30,7 @@ import invoice
|
||||
import overdue
|
||||
import aged_trial_balance
|
||||
import tax_report
|
||||
import account_tax_code
|
||||
#import account_tax_code
|
||||
import account_balance_landscape
|
||||
import compare_account_balance
|
||||
import account_invoice_report
|
||||
|
||||
+21
-11
@@ -602,7 +602,7 @@ class stock_picking(osv.osv):
|
||||
("2binvoiced", "To Be Invoiced"),
|
||||
("none", "Not from Picking")], "Invoice Status",
|
||||
select=True, required=True, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, select=1),
|
||||
}
|
||||
_defaults = {
|
||||
'name': lambda self, cr, uid, context: '/',
|
||||
@@ -1384,7 +1384,7 @@ class stock_move(osv.osv):
|
||||
\nThe state is \'Waiting\' if the move is waiting for another one.'),
|
||||
'price_unit': fields.float('Unit Price',
|
||||
digits_compute= dp.get_precision('Account')),
|
||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, select=1),
|
||||
'partner_id': fields.related('picking_id','address_id','partner_id',type='many2one', relation="res.partner", string="Partner"),
|
||||
'backorder_id': fields.related('picking_id','backorder_id',type='many2one', relation="stock.picking", string="Back Order"),
|
||||
'origin': fields.related('picking_id','origin',type='char', size=64, relation="stock.picking", string="Origin"),
|
||||
@@ -1693,15 +1693,25 @@ class stock_move(osv.osv):
|
||||
new_move = []
|
||||
update_val = {}
|
||||
ir_sequence_obj = self.pool.get('ir.sequence')
|
||||
prodlot_obj = self.pool.get('stock.production.lot')
|
||||
last_prod = [line.prodlot_id for line in self.browse(cr, uid, ids)[0].picking_id.move_lines if line.prodlot_id]
|
||||
last_prod.sort(key=lambda p: p.date, reverse=True)
|
||||
last_prod_id = last_prod and last_prod[0].id
|
||||
update_val['prodlot_id'] = last_prod_id
|
||||
if update_val.get('prodlot_id',[])==[]:
|
||||
sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial')
|
||||
prodlot_id = prodlot_obj.create(cr, uid, {'name': sequence}, {'product_id': self.browse(cr, uid, ids)[0].product_id.id})
|
||||
update_val['prodlot_id'] = prodlot_id
|
||||
tracking_obj = self.pool.get('stock.tracking')
|
||||
tracking = False
|
||||
tracking = context.get('tracking', False)
|
||||
# import pdb; pdb.set_trace()
|
||||
if tracking:
|
||||
tracking_id = tracking_obj.search(cr, uid, ['name','=', tracking])
|
||||
if prodlot_id:
|
||||
update_val['prodlot_id'] = prodlot_id
|
||||
else:
|
||||
tracking_id = tracking_obj.create(cr, uid, {'name': tracking}, {'product_id': self.browse(cr, uid, ids)[0].product_id.id})
|
||||
update_val['tracking_id'] = tracking_id
|
||||
else:
|
||||
last_track = [line.tracking_id for line in self.browse(cr, uid, ids)[0].picking_id.move_lines if line.tracking_id]
|
||||
if not last_track:
|
||||
track_ids= tracking_obj.search(cr, uid, [])
|
||||
last_track = [track for track in tracking_obj.browse(cr, uid, track_ids)]
|
||||
last_track.sort(key=lambda p: p.date, reverse=True)
|
||||
last_track_id = last_track and last_track[0].id
|
||||
update_val['tracking_id'] = last_track_id
|
||||
self.write(cr, uid, ids, update_val)
|
||||
return True
|
||||
|
||||
|
||||
@@ -1630,6 +1630,10 @@
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_planned'}" />
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Extended options..." groups="base.group_extended">
|
||||
<field name="tracking_id" context="{'tracking': self}" domain="[]" />
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# 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 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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 stock_avg_consommation
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# 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 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
'name': 'Stock Average consommation',
|
||||
'version': '1.0',
|
||||
'category': 'Generic Modules/Inventory Control',
|
||||
'author': 'Tiny',
|
||||
'depends': ['stock'],
|
||||
'init_xml': [],
|
||||
'update_xml': ['stock_avg_consommation_view.xml'],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,100 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# 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 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv
|
||||
import tools
|
||||
import ir
|
||||
import pooler
|
||||
from mx import DateTime
|
||||
from datetime import datetime
|
||||
import time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
class stock_avg_consommation(osv.osv):
|
||||
_name = "stock.avg.consommation"
|
||||
_inherit="product.product"
|
||||
|
||||
def _compute_avg_consommation(self, cr, uid, ids, fields, args, context={}):
|
||||
print ids, fields, args, context
|
||||
date_str=False
|
||||
from_date=context.get('from_date',False)
|
||||
to_date=context.get('to_date',False)
|
||||
|
||||
if from_date and to_date:
|
||||
date_str="date_planned>='%s' and date_planned<='%s'"%(from_date,to_date)
|
||||
elif from_date:
|
||||
date_str="date_planned>='%s'"%(from_date)
|
||||
elif to_date:
|
||||
date_str="date_planned<='%s'"%(to_date)
|
||||
|
||||
date_object_to = to_date and datetime.strptime(to_date, '%Y-%m-%d %H:%M:%S') or datetime.now()
|
||||
date_object_from = from_date and datetime.strptime(from_date, '%Y-%m-%d %H:%M:%S') or (datetime.now() + relativedelta(days=-30))
|
||||
dd = date_object_to - date_object_from
|
||||
total_days=dd.days+1
|
||||
if not from_date and not to_date:
|
||||
date_str="date_planned>='%s' and date_planned<='%s'"%(date_object_from.strftime('%Y-%m-%d 00:00:00'), date_object_to.strftime('%Y-%m-%d 23:59:59'))
|
||||
elif not from_date:
|
||||
date_str="date_planned>='%s'"%(date_object_from.strftime('%Y-%m-%d 00:00:00'))
|
||||
elif not to_date:
|
||||
date_str="date_planned<='%s'"%(date_object_to.strftime('%Y-%m-%d 23:59:59'))
|
||||
res={}
|
||||
for line_id in ids:
|
||||
res[line_id] = False
|
||||
location_ids = []
|
||||
|
||||
if context.get('location', False):
|
||||
if type(context['location']) == type(1):
|
||||
location_ids = [context['location']]
|
||||
elif type(context['location']) in (type(''), type(u'')):
|
||||
location_ids = self.pool.get('stock.location').search(cr, uid, [('name','ilike',context['location'])], context=context)
|
||||
else:
|
||||
location_ids = context['location']
|
||||
else:
|
||||
location_ids = []
|
||||
wids = self.pool.get('stock.warehouse').search(cr, uid, [], context=context)
|
||||
for w in self.pool.get('stock.warehouse').browse(cr, uid, wids, context=context):
|
||||
location_ids.append(w.lot_stock_id.id)
|
||||
|
||||
# build the list of ids of children of the location given by id
|
||||
if context.get('compute_child',True):
|
||||
child_location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids)])
|
||||
location_ids = child_location_ids or location_ids
|
||||
else:
|
||||
location_ids = location_ids
|
||||
|
||||
|
||||
|
||||
#sql = """select product_id,sum(product_qty) from stock_move sm,stock_picking sp where sm.picking_id=sp.id and sp.type in ('out','delivery') and %s and location_id <> ANY(%s) and location_dest_id =ANY(%s) group by product_id""" % (date_str, location_ids, location_ids)
|
||||
sql = """select product_id,sum(product_qty) from stock_move sm,stock_picking sp where sm.picking_id=sp.id and sp.type in ('out','delivery') and """+date_str+""" and sm.location_id not in %s and sm.location_dest_id in %s group by product_id"""
|
||||
cr.execute(sql, [tuple(location_ids), tuple(location_ids)])
|
||||
product_ids = []
|
||||
res_sum = cr.fetchall()
|
||||
for line_id, avg in res_sum:
|
||||
res[line_id] = avg/total_days
|
||||
product_ids.append(avg)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'avg_consommation':fields.function(_compute_avg_consommation,method=True, type='float', string="Average Consommation"),
|
||||
}
|
||||
stock_avg_consommation()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="stock_avg_consommation_tree" model="ir.ui.view">
|
||||
<field name="name">stock.avg.consommation.tree</field>
|
||||
<field name="model">stock.avg.consommation</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="state" position="after">
|
||||
<field name="avg_consommation" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# 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 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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 stock_avg_consommation_wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# 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 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
|
||||
class stock_location_product(osv.osv_memory):
|
||||
_inherit = "stock.location.product"
|
||||
|
||||
def action_open_window(self, cr, uid, ids, context):
|
||||
""" To open location wise product information specific to given duration
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param ids: An ID or list of IDs if we want more than one
|
||||
@param context: A standard dictionary
|
||||
@return: Invoice type
|
||||
"""
|
||||
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
view = mod_obj._get_id(cr, uid, 'stock_avg_consommation', 'stock_avg_consommation_tree')
|
||||
id = mod_obj.read(cr, uid, view, ['res_id'])
|
||||
|
||||
for location_obj in self.read(cr, uid, ids, ['from_date', 'to_date']):
|
||||
return {
|
||||
'name': False,
|
||||
'view_id':[id['res_id']],
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'stock.avg.consommation',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'location': context['active_id'],
|
||||
'from_date': location_obj['from_date'],
|
||||
'to_date': location_obj['to_date']},
|
||||
'domain': [('type', '<>', 'service')],
|
||||
}
|
||||
|
||||
stock_location_product()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -68,7 +68,7 @@ class procurement_order(osv.osv):
|
||||
origin = (proc.origin or proc.name or '').split(':')[0] +':'+line.name
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, {
|
||||
'origin': origin,
|
||||
'company_id': line.chained_company_id and line.chained_company_id.id or False,
|
||||
'company_id': line.company_id and line.company_id.id or False,
|
||||
'type': line.picking_type,
|
||||
'stock_journal_id': line.journal_id and line.journal_id.id or False,
|
||||
'move_type': 'one',
|
||||
@@ -79,7 +79,7 @@ class procurement_order(osv.osv):
|
||||
move_id = self.pool.get('stock.move').create(cr, uid, {
|
||||
'name': line.name,
|
||||
'picking_id': picking_id,
|
||||
'company_id': line.chained_company_id and line.chained_company_id.id or False,
|
||||
'company_id': line.company_id and line.company_id.id or False,
|
||||
'product_id': proc.product_id.id,
|
||||
'date_planned': proc.date_planned,
|
||||
'product_qty': proc.product_qty,
|
||||
|
||||
@@ -40,7 +40,6 @@ class stock_location_path(osv.osv):
|
||||
("none", "Not from Picking")], "Invoice Status",
|
||||
required=True,),
|
||||
'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal'),('delivery','Delivery')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
|
||||
'chained_company_id': fields.many2one('res.company', 'Chained Company', help='Set here the belonging company of the chained move'),
|
||||
'auto': fields.selection(
|
||||
[('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')],
|
||||
'Automatic Move',
|
||||
@@ -73,7 +72,6 @@ class product_pulled_flow(osv.osv):
|
||||
'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company belong packings and moves"),
|
||||
'partner_address_id': fields.many2one('res.partner.address', 'Partner Address'),
|
||||
'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal'),('delivery','Delivery')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
|
||||
'chained_company_id': fields.many2one('res.company', 'Chained Company', help='Set here the belonging company of the chained move'),
|
||||
'product_id':fields.many2one('product.product','Product'),
|
||||
'invoice_state': fields.selection([
|
||||
("invoiced", "Invoiced"),
|
||||
@@ -120,7 +118,7 @@ class stock_location(osv.osv):
|
||||
if product:
|
||||
for path in product.path_ids:
|
||||
if path.location_from_id.id == location.id:
|
||||
return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.chained_company_id and path.chained_companyd_id.id or False, path.picking_type
|
||||
return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.company_id and path.company_id.id or False, path.picking_type
|
||||
return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context)
|
||||
stock_location()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user