[MERGE]: merged the branch with module1_addons

bzr revid: mso@mso-20100318093558-yu7mliu8bgpdh3kq
This commit is contained in:
mso 2010-03-18 15:05:58 +05:30
commit 7b678a4a1b
40 changed files with 661 additions and 231 deletions

View File

@ -19,18 +19,6 @@
#
##############################################################################
#import wizard_aie_send
#import wizard_aie_send_result
#import wizard_lots_buyer_map
#import wizard_lots_cancel
#import wizard_lots_invoice
#import wizard_lots_numerotate
#import wizard_lots_pay
#import wizard_pay
#import wizard_lot_date_move
#import wizard_transfer_unsold_object
#import auction_catalog_flagey
import auction_lots_able
import auction_lots_enable
import auction_lots_make_invoice_buyer

View File

@ -36,7 +36,7 @@ class make_delivery(osv.osv_memory):
def default_get(self, cr, uid, fields, context):
"""
@summary: To get default values for the object.
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@ -63,7 +63,7 @@ class make_delivery(osv.osv_memory):
def delivery_set(self, cr, uid, ids, context):
"""
@summary: Adds delivery costs to Sale Order Line.
Adds delivery costs to Sale Order Line.
@param self: The object pointer.
@param cr: A database cursor

View File

@ -1285,5 +1285,201 @@ class mrp_procurement(osv.osv):
self._procure_orderpoint_confirm(cr, uid, automatic=automatic,\
use_new_cursor=use_new_cursor, context=context)
mrp_procurement()
class stock_warehouse_orderpoint(osv.osv):
_name = "stock.warehouse.orderpoint"
_description = "Orderpoint minimum rule"
_columns = {
'name': fields.char('Name', size=32, required=True),
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the orderpoint without removing it."),
'logic': fields.selection([('max','Order to Max'),('price','Best price (not yet active!)')], 'Reordering Mode', required=True),
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
'location_id': fields.many2one('stock.location', 'Location', required=True),
'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', required=True, domain=[('type','=','product')]),
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True ),
'product_min_qty': fields.float('Min Quantity', required=True,
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
"a requisition to bring the virtual stock to the Max Quantity."),
'product_max_qty': fields.float('Max Quantity', required=True,
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
"a requisition to bring the virtual stock to the Max Quantity."),
'qty_multiple': fields.integer('Qty Multiple', required=True,
help="The requisition quantity will by rounded up to this multiple."),
'procurement_id': fields.many2one('mrp.procurement', 'Latest Requisition'),
'company_id': fields.many2one('res.company','Company',required=True),
}
_defaults = {
'active': lambda *a: 1,
'logic': lambda *a: 'max',
'qty_multiple': lambda *a: 1,
'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'mrp.warehouse.orderpoint') or '',
'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c)
}
def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context={}):
if warehouse_id:
w=self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
v = {'location_id':w.lot_stock_id.id}
return {'value': v}
return {}
def onchange_product_id(self, cr, uid, ids, product_id, context={}):
if product_id:
prod=self.pool.get('product.product').browse(cr,uid,product_id)
v = {'product_uom':prod.uom_id.id}
return {'value': v}
return {}
def copy(self, cr, uid, id, default=None,context={}):
if not default:
default = {}
default.update({
'name': self.pool.get('ir.sequence').get(cr, uid, 'mrp.warehouse.orderpoint') or '',
})
return super(stock_warehouse_orderpoint, self).copy(cr, uid, id, default, context)
stock_warehouse_orderpoint()
class StockMove(osv.osv):
_inherit = 'stock.move'
_columns = {
'procurements': fields.one2many('mrp.procurement', 'move_id', 'Requisitions'),
}
def copy(self, cr, uid, id, default=None, context=None):
default = default or {}
default['procurements'] = []
return super(StockMove, self).copy(cr, uid, id, default, context)
def _action_explode(self, cr, uid, move, context={}):
if move.product_id.supply_method=='produce' and move.product_id.procure_method=='make_to_order':
bis = self.pool.get('mrp.bom').search(cr, uid, [
('product_id','=',move.product_id.id),
('bom_id','=',False),
('type','=','phantom')])
if bis:
factor = move.product_qty
bom_point = self.pool.get('mrp.bom').browse(cr, uid, bis[0])
res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor, [])
dest = move.product_id.product_tmpl_id.property_stock_production.id
state = 'confirmed'
if move.state=='assigned':
state='assigned'
for line in res[0]:
valdef = {
'picking_id': move.picking_id.id,
'product_id': line['product_id'],
'product_uom': line['product_uom'],
'product_qty': line['product_qty'],
'product_uos': line['product_uos'],
'product_uos_qty': line['product_uos_qty'],
'move_dest_id': move.id,
'state': state,
'name': line['name'],
'location_dest_id': dest,
'move_history_ids': [(6,0,[move.id])],
'move_history_ids2': [(6,0,[])],
'procurements': [],
}
mid = self.pool.get('stock.move').copy(cr, uid, move.id, default=valdef)
prodobj = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=context)
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
'name': (move.picking_id.origin or ''),
'origin': (move.picking_id.origin or ''),
'date_planned': move.date_planned,
'product_id': line['product_id'],
'product_qty': line['product_qty'],
'product_uom': line['product_uom'],
'product_uos_qty': line['product_uos'] and line['product_uos_qty'] or False,
'product_uos': line['product_uos'],
'location_id': move.location_id.id,
'procure_method': prodobj.procure_method,
'move_id': mid,
'company_id': line['company_id'],
})
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
self.pool.get('stock.move').write(cr, uid, [move.id], {
'location_id': move.location_dest_id.id,
'auto_validate': True,
'picking_id': False,
'location_id': dest,
'state': 'waiting'
})
for m in self.pool.get('mrp.procurement').search(cr, uid, [('move_id','=',move.id)], context):
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'mrp.procurement', m, 'button_wait_done', cr)
return True
def consume_moves(self, cr, uid, ids, product_qty, location_id=False, location_dest_id=False, consume=True, context=None):
res = []
production_obj = self.pool.get('mrp.production')
wf_service = netsvc.LocalService("workflow")
for move in self.browse(cr, uid, ids):
new_moves = super(StockMove, self).consume_moves(cr, uid, [move.id], product_qty, location_id, location_dest_id, consume, context=context)
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
for prod in production_obj.browse(cr, uid, production_ids, context=context):
if prod.state == 'confirmed':
production_obj.force_production(cr, uid, [prod.id])
wf_service.trg_validate(uid, 'mrp.production', prod.id, 'button_produce', cr)
for new_move in new_moves:
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
res.append(new_move)
return res
def scrap_moves(self, cr, uid, ids, product_qty, location_id, context=None):
res = []
production_obj = self.pool.get('mrp.production')
wf_service = netsvc.LocalService("workflow")
for move in self.browse(cr, uid, ids):
new_moves = super(StockMove, self).scrap_moves(cr, uid, [move.id], product_qty, location_id, context=context)
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
for prod_id in production_ids:
wf_service.trg_validate(uid, 'mrp.production', prod_id, 'button_produce', cr)
for new_move in new_moves:
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
res.append(new_move)
return {}
StockMove()
class StockPicking(osv.osv):
_inherit = 'stock.picking'
def test_finnished(self, cursor, user, ids):
wf_service = netsvc.LocalService("workflow")
res = super(StockPicking, self).test_finnished(cursor, user, ids)
for picking in self.browse(cursor, user, ids):
for move in picking.move_lines:
if move.state == 'done' and move.procurements:
for procurement in move.procurements:
wf_service.trg_validate(user, 'mrp.procurement',
procurement.id, 'button_check', cursor)
return res
#
# Explode picking by replacing phantom BoMs
#
def action_explode(self, cr, uid, picks, *args):
for move in self.pool.get('stock.move').browse(cr, uid, picks):
self.pool.get('stock.move')._action_explode(cr, uid, move)
return picks
StockPicking()
class spilt_in_production_lot(osv.osv_memory):
_inherit = "stock.move.split"
def split(self, cr, uid, ids, move_ids, context=None):
production_obj = self.pool.get('mrp.production')
move_obj = self.pool.get('stock.move')
res = []
for move in move_obj.browse(cr, uid, move_ids, context=context):
new_moves = super(spilt_in_production_lot, self).split(cr, uid, ids, move_ids, context=context)
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
for new_move in new_moves:
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
return res
spilt_in_production_lot()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -36,7 +36,7 @@ class change_production_qty(osv.osv_memory):
def default_get(self, cr, uid, fields, context):
"""
@summary: To get default values for the object.
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@ -61,7 +61,7 @@ class change_production_qty(osv.osv_memory):
def change_prod_qty(self, cr, uid, ids, context):
"""
@summary: Changes the Quantity of Product.
Changes the Quantity of Product.
@param self: The object pointer.
@param cr: A database cursor

View File

@ -30,7 +30,7 @@ class make_procurement(osv.osv_memory):
def onchange_product_id(self, cr, uid, ids, prod_id):
"""
@summary: On Change of Product ID getting the value of related UoM.
On Change of Product ID getting the value of related UoM.
@param self: The object pointer.
@param cr: A database cursor
@ -59,7 +59,7 @@ class make_procurement(osv.osv_memory):
def make_procurement(self, cr, uid, ids, context=None):
"""
@summary: Creates procurement order for selected product.
Creates procurement order for selected product.
@param self: The object pointer.
@param cr: A database cursor
@ -110,7 +110,7 @@ class make_procurement(osv.osv_memory):
def default_get(self, cr, uid, fields, context=None):
"""
@summary: To get default values for the object.
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor

View File

@ -35,7 +35,7 @@ class mrp_product_produce(osv.osv_memory):
def _get_product_qty(self, cr, uid, context):
"""
@summary: to obtain product quantity
To obtain product quantity
@param self: The object pointer.
@param cr: A database cursor
@ -58,7 +58,7 @@ class mrp_product_produce(osv.osv_memory):
def do_produce(self, cr, uid, ids, context={}):
"""
@summary: to check the product type
To check the product type
@param self: The object pointer.
@param cr: A database cursor

View File

@ -29,7 +29,7 @@ class repair_cancel(osv.osv_memory):
def cancel_repair(self, cr, uid, ids, context):
"""
@summary: Cancels the repair
Cancels the repair
@param self: The object pointer.
@param cr: A database cursor
@ -55,7 +55,7 @@ class repair_cancel(osv.osv_memory):
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
@summary: Changes the view dynamically
Changes the view dynamically
@param self: The object pointer.
@param cr: A database cursor

View File

@ -32,7 +32,7 @@ class make_invoice(osv.osv_memory):
def make_invoices(self, cr, uid, ids, context):
"""
@summary: Generates invoice(s) of selected records.
Generates invoice(s) of selected records.
@param self: The object pointer.
@param cr: A database cursor

View File

@ -37,7 +37,7 @@ class add_product(osv.osv_memory):
def select_product(self, cr, uid, ids, context):
"""
@summary: To get the product and quantity and add in order .
To get the product and quantity and add in order .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -28,7 +28,7 @@ from tools.translate import _
def get_journal(self,cr,uid,context):
"""
@summary: Make the selection list of Cash Journal .
Make the selection list of Cash Journal .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@ -53,7 +53,7 @@ class pos_box_entries(osv.osv_memory):
def _get_income_product(self,cr,uid,context):
"""
@summary: Make the selection list of purchasing products.
Make the selection list of purchasing products.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@ -84,7 +84,7 @@ class pos_box_entries(osv.osv_memory):
"""
@summary: Create the entry of statement in journal .
Create the entry of statement in journal .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -35,7 +35,7 @@ class pos_box_out(osv.osv_memory):
def _get_expense_product(self,cr,uid,context):
"""
@summary: Make the selection list of expense product.
Make the selection list of expense product.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@ -64,7 +64,7 @@ class pos_box_out(osv.osv_memory):
def get_out(self, cr, uid, ids, context):
"""
@summary: Create the entries in the CashBox .
Create the entries in the CashBox .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -31,7 +31,7 @@ class pos_close_statement(osv.osv_memory):
def close_statement(self, cr, uid, ids, context):
"""
@summary: Close the statements
Close the statements
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -28,7 +28,7 @@ class pos_confirm(osv.osv_memory):
_description = 'Point of Sale Confirm'
def action_confirm(self, cr, uid, ids, context):
"""
@summary: Confirm the order and close the sales .
Confirm the order and close the sales .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -37,7 +37,7 @@ class pos_discount(osv.osv_memory):
def apply_discount(self, cr, uid, ids, context):
"""
@summary: To give the discount of product and check the .
To give the discount of product and check the .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@ -82,7 +82,7 @@ class pos_discount(osv.osv_memory):
def check_discount(self, cr, uid, record_id,discount, context):
"""
@summary: Check the discount of define by company .
Check the discount of define by company .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -33,7 +33,7 @@ class pos_get_sale(osv.osv_memory):
def sale_complete(self, cr, uid, ids, context):
"""
@summary: Select the picking order and add the in Point of sale order
Select the picking order and add the in Point of sale order
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -30,7 +30,7 @@ class pos_open_statement(osv.osv_memory):
def open_statement(self, cr, uid, ids, context):
"""
@summary: open the statements
Open the statements
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in

View File

@ -208,7 +208,13 @@ class product_category(osv.osv):
'parent_id': fields.many2one('product.category','Parent Category', select=True),
'child_id': fields.one2many('product.category', 'parent_id', string='Child Categories'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type'),
}
_defaults = {
'type' : lambda *a : 'normal',
}
_order = "sequence"
def _check_recursion(self, cr, uid, ids):
level = 100

View File

@ -217,6 +217,7 @@
<field name="name" select="1"/>
<field name="parent_id"/>
<field name="sequence"/>
<field name="type"/>
<newline/>
</form>
</field>

View File

@ -34,8 +34,6 @@ class product_margin(osv.osv_memory):
def action_open_window(self, cr, uid, ids, context):
"""
@summary:
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: the ID or list of IDs if we want more than one

View File

@ -36,9 +36,9 @@
'purchase_workflow.xml',
'purchase_sequence.xml',
'purchase_data.xml',
'wizard/purchase_order_group_view.xml',
'purchase_view.xml',
'purchase_report.xml',
'purchase_wizard.xml',
'stock_view.xml',
'partner_view.xml',
'process/purchase_process.xml',

View File

@ -288,6 +288,15 @@
name="Product purchases"
res_model="purchase.order.line"
src_model="product.product"/>
<!--
<record model="ir.values" id="action_merge_purchase_order">
<field name="object" eval="1" />
<field name="name">Purchase Order</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_view_purchase_order_group'))" />
<field name="key">action</field>
<field name="model">purchase.order</field>
</record>
-->
</data>
</openerp>

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--
<wizard id="purchase_order_merge"
model="purchase.order"
multi="True"
keyword="client_action_multi"
name="purchase.order.merge"
string="Merge purchases"/>
-->
</data>
</openerp>

View File

@ -19,7 +19,7 @@
#
##############################################################################
import wizard_group
import purchase_order_group
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,162 @@
# -*- 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
from service import web_services
import netsvc
import pooler
import time
import wizard
from osv.orm import browse_record, browse_null
class purchase_order_group(osv.osv_memory):
_name = "purchase.order.group"
_description = "Purchase Wizard"
_columns = {
}
def merge_orders(self, cr, uid, ids, context):
"""
To merge similar type of purchase orders.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: the ID or list of IDs
@param context: A standard dictionary
@return: purchase order view
"""
order_obj = self.pool.get('purchase.order')
mod_obj =self.pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'purchase', 'view_purchase_order_filter')
id = mod_obj.read(cr, uid, result, ['res_id'])
def make_key(br, fields):
"""
Returns tuple indicating the value corresponding to fields
@param br: record object
@param fields: name of fields
@return: Returns tuple indicating the value corresponding to fields
"""
list_key = []
for field in fields:
field_val = getattr(br, field)
if field in ('product_id', 'move_dest_id', 'account_analytic_id'):
if not field_val:
field_val = False
if isinstance(field_val, browse_record):
field_val = field_val.id
elif isinstance(field_val, browse_null):
field_val = False
elif isinstance(field_val, list):
field_val = ((6, 0, tuple([v.id for v in field_val])),)
list_key.append((field, field_val))
list_key.sort()
return tuple(list_key)
# compute what the new orders should contain
new_orders = {}
for porder in [order for order in order_obj.browse(cr, uid, context['active_ids']) if order.state == 'draft']:
order_key = make_key(porder, ('partner_id', 'location_id', 'pricelist_id'))
new_order = new_orders.setdefault(order_key, ({}, []))
new_order[1].append(porder.id)
order_infos = new_order[0]
if not order_infos:
order_infos.update({
'origin': porder.origin,
'date_order': time.strftime('%Y-%m-%d'),
'partner_id': porder.partner_id.id,
'partner_address_id': porder.partner_address_id.id,
'dest_address_id': porder.dest_address_id.id,
'warehouse_id': porder.warehouse_id.id,
'location_id': porder.location_id.id,
'pricelist_id': porder.pricelist_id.id,
'state': 'draft',
'order_line': {},
'notes': '%s' % (porder.notes or '',),
})
else:
#order_infos['name'] += ', %s' % porder.name
if porder.notes:
order_infos['notes'] = (order_infos['notes'] or '') + ('\n%s' % (porder.notes,))
if porder.origin:
order_infos['origin'] = (order_infos['origin'] or '') + ' ' + porder.origin
for order_line in porder.order_line:
line_key = make_key(order_line, ('name', 'date_planned', 'taxes_id', 'price_unit', 'notes', 'product_id', 'move_dest_id', 'account_analytic_id'))
o_line = order_infos['order_line'].setdefault(line_key, {})
if o_line:
# merge the line with an existing line
o_line['product_qty'] += order_line.product_qty * order_line.product_uom.factor / o_line['uom_factor']
else:
# append a new "standalone" line
for field in ('product_qty', 'product_uom'):
field_val = getattr(order_line, field)
if isinstance(field_val, browse_record):
field_val = field_val.id
o_line[field] = field_val
o_line['uom_factor'] = order_line.product_uom and order_line.product_uom.factor or 1.0
wf_service = netsvc.LocalService("workflow")
allorders = []
for order_key, (order_data, old_ids) in new_orders.iteritems():
# skip merges with only one order
if len(old_ids) < 2:
allorders += (old_ids or [])
continue
# cleanup order line data
for key, value in order_data['order_line'].iteritems():
del value['uom_factor']
value.update(dict(key))
order_data['order_line'] = [(0, 0, value) for value in order_data['order_line'].itervalues()]
# create the new order
neworder_id = order_obj.create(cr, uid, order_data)
allorders.append(neworder_id)
# make triggers pointing to the old orders point to the new order
for old_id in old_ids:
wf_service.trg_redirect(uid, 'purchase.order', old_id, neworder_id, cr)
wf_service.trg_validate(uid, 'purchase.order', old_id, 'purchase_cancel', cr)
return {
'domain': "[('id','in', [" + ','.join(map(str, allorders)) + "])]",
'name': 'Purchase Orders',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'purchase.order',
'view_id': False,
'type': 'ir.actions.act_window',
'search_view_id': id['res_id']
}
purchase_order_group()

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_purchase_order_group" model="ir.ui.view">
<field name="name">Merger Purchase Orders</field>
<field name="model">purchase.order.group</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Merge orders">
<separator string="Are you sure you want to merge these orders ?" colspan="4"/>
<newline/>
<label string="Please note that:" colspan="4"/>
<newline/>
<label string="-orders will only be merged if:" colspan="4"/>
<newline/>
<label string="* their status is draft" colspan="4"/>
<newline/>
<label string="* they belong to the same partner" colspan="4"/>
<newline/>
<label string="* are going to the same location" colspan="4"/>
<newline/>
<label string="* have the same pricelist" colspan="4"/>
<newline/>
<label string="- lines will only be merged if:" colspan="4"/>
<newline/>
<label string="* they are exactly the same except for the quantity and unit" colspan="4"/>
<separator string="" colspan="4" />
<button special="cancel" string="Cancel" />
<button name="merge_orders" string="Merge orders" type="object" />
</form>
</field>
</record>
<act_window name="Merge Purchase orders"
res_model="purchase.order.group"
src_model="purchase.order"
view_mode="form"
target="new"
key2="client_action_multi"
id="action_view_purchase_order_group"/>
</data>
</openerp>

View File

@ -1,173 +0,0 @@
# -*- 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 time
import wizard
import netsvc
import pooler
from osv.orm import browse_record, browse_null
merge_form = """<?xml version="1.0"?>
<form string="Merge orders">
<separator string="Are you sure you want to merge these orders ?"/>
<newline/>
<label>Please note that:
- orders will only be merged if:
* their status is draft
* they belong to the same partner
* are going to the same location
* have the same pricelist
- lines will only be merged if:
* they are exactly the same except for the quantity and unit</label>
</form>
"""
merge_fields = {
}
ack_form = """<?xml version="1.0"?>
<form string="Merge orders">
<separator string="Orders merged"/>
</form>"""
ack_fields = {}
def _merge_orders(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
order_obj = pool.get('purchase.order')
mod_obj = pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'purchase', 'view_purchase_order_filter')
id = mod_obj.read(cr, uid, result, ['res_id'])
def make_key(br, fields):
list_key = []
for field in fields:
field_val = getattr(br, field)
if field in ('product_id', 'move_dest_id', 'account_analytic_id'):
if not field_val:
field_val = False
if isinstance(field_val, browse_record):
field_val = field_val.id
elif isinstance(field_val, browse_null):
field_val = False
elif isinstance(field_val, list):
field_val = ((6, 0, tuple([v.id for v in field_val])),)
list_key.append((field, field_val))
list_key.sort()
return tuple(list_key)
# compute what the new orders should contain
new_orders = {}
for porder in [order for order in order_obj.browse(cr, uid, data['ids']) if order.state == 'draft']:
order_key = make_key(porder, ('partner_id', 'location_id', 'pricelist_id'))
new_order = new_orders.setdefault(order_key, ({}, []))
new_order[1].append(porder.id)
order_infos = new_order[0]
if not order_infos:
order_infos.update({
'origin': porder.origin,
'date_order': time.strftime('%Y-%m-%d'),
'partner_id': porder.partner_id.id,
'partner_address_id': porder.partner_address_id.id,
'dest_address_id': porder.dest_address_id.id,
'warehouse_id': porder.warehouse_id.id,
'location_id': porder.location_id.id,
'pricelist_id': porder.pricelist_id.id,
'state': 'draft',
'order_line': {},
'notes': '%s' % (porder.notes or '',),
})
else:
#order_infos['name'] += ', %s' % porder.name
if porder.notes:
order_infos['notes'] = (order_infos['notes'] or '') + ('\n%s' % (porder.notes,))
if porder.origin:
order_infos['origin'] = (order_infos['origin'] or '') + ' ' + porder.origin
for order_line in porder.order_line:
line_key = make_key(order_line, ('name', 'date_planned', 'taxes_id', 'price_unit', 'notes', 'product_id', 'move_dest_id', 'account_analytic_id'))
o_line = order_infos['order_line'].setdefault(line_key, {})
if o_line:
# merge the line with an existing line
o_line['product_qty'] += order_line.product_qty * order_line.product_uom.factor / o_line['uom_factor']
else:
# append a new "standalone" line
for field in ('product_qty', 'product_uom'):
field_val = getattr(order_line, field)
if isinstance(field_val, browse_record):
field_val = field_val.id
o_line[field] = field_val
o_line['uom_factor'] = order_line.product_uom and order_line.product_uom.factor or 1.0
wf_service = netsvc.LocalService("workflow")
allorders = []
for order_key, (order_data, old_ids) in new_orders.iteritems():
# skip merges with only one order
if len(old_ids) < 2:
allorders += (old_ids or [])
continue
# cleanup order line data
for key, value in order_data['order_line'].iteritems():
del value['uom_factor']
value.update(dict(key))
order_data['order_line'] = [(0, 0, value) for value in order_data['order_line'].itervalues()]
# create the new order
neworder_id = order_obj.create(cr, uid, order_data)
allorders.append(neworder_id)
# make triggers pointing to the old orders point to the new order
for old_id in old_ids:
wf_service.trg_redirect(uid, 'purchase.order', old_id, neworder_id, cr)
wf_service.trg_validate(uid, 'purchase.order', old_id, 'purchase_cancel', cr)
return {
'domain': "[('id','in', [" + ','.join(map(str, allorders)) + "])]",
'name': 'Purchase Orders',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'purchase.order',
'view_id': False,
'type': 'ir.actions.act_window',
'search_view_id': id['res_id']
}
class merge_orders(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch': merge_form, 'fields' : merge_fields, 'state' : [('end', 'Cancel'), ('merge', 'Merge orders') ]}
},
'merge': {
'actions': [],
'result': {'type': 'action', 'action': _merge_orders, 'state': 'end'}
},
}
merge_orders("purchase.order.merge")

View File

@ -38,7 +38,7 @@ class sale_order_line_make_invoice(osv.osv_memory):
def make_invoices(self, cr, uid, ids, context):
"""
@summary: To make invoices.
To make invoices.
@param self: The object pointer.
@param cr: A database cursor
@ -56,7 +56,7 @@ class sale_order_line_make_invoice(osv.osv_memory):
#TODO: merge with sale.py/make_invoice
def make_invoice(order, lines):
"""
@summary: To make invoices.
To make invoices.
@param order:
@param lines:

View File

@ -40,7 +40,7 @@ class sale_advance_payment_inv(osv.osv_memory):
}
def create_invoices(self, cr, uid, ids, context={}):
"""
@summary: To create invoices.
To create invoices.
@param self: The object pointer.
@param cr: A database cursor
@ -143,7 +143,7 @@ class sale_open_invoice(osv.osv_memory):
def open_invoice(self, cr, uid, ids, context):
"""
@summary: To open invoice.
To open invoice.
@param self: The object pointer.
@param cr: A database cursor

View File

@ -48,6 +48,7 @@ Thanks to the double entry management, the inventory controlling is powerful and
"wizard/stock_invoice_onshipping_view.xml",
"wizard/stock_location_product_view.xml",
"wizard/stock_inventory_line_split_view.xml",
"wizard/stock_change_standard_price_view.xml",
"stock_workflow.xml",
"stock_incoterms.xml",
"stock_wizard.xml",

View File

@ -54,6 +54,20 @@
</field>
</record>
<record id="view_product_standard_price_form" model="ir.ui.view">
<field name="name">product.product.standard.price.form.inherit</field>
<field name="model">product.product</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<field name="standard_price" position="replace">
<group col="4" colspan="2">
<field name="standard_price" readonly="True"/>
<button name="%(action_view_change_standard_price)d" string="Change Price" type="action" icon="gtk-execute"/>
</group>
</field>
</field>
</record>
<record id="view_normal_property_acc_form" model="ir.ui.view">
<field name="name">product.normal.stock.acc.property.form.inherit</field>

View File

@ -154,7 +154,7 @@
</record>
<record model="ir.actions.act_window" id="action_stock_line_date">
<field name="name">Latest Inventory Date by Product</field>
<field name="name">Latest Inventories Dates by Product</field>
<field name="res_model">report.stock.lines.date</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>

View File

@ -36,5 +36,7 @@ import stock_inventory_line_split
import stock_invoice_onshipping
import stock_location_product
import stock_change_standard_price
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,149 @@
# -*- 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
from tools.translate import _
class change_standard_price(osv.osv_memory):
_name = "stock.change.standard.price"
_description = "Change Standard Price"
_columns = {
'new_price': fields.float('Price', required=True),
}
def default_get(self, cr, uid, fields, context):
"""
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
rec_id = context and context.get('active_id', False)
res = {}
price = self.pool.get('product.product').browse(cr, uid, rec_id)
res['new_price'] = price.standard_price
return res
def change_price(self, cr, uid, ids, context):
"""
Changes the Standard Price of Product.
And creates an account move accordingly.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of IDs selected
@param context: A standard dictionary
@return:
"""
rec_id = context and context.get('active_id', False)
prod_obj = self.pool.get('product.template')
location_obj = self.pool.get('stock.location')
lot_obj = self.pool.get('stock.report.prodlots')
move_obj = self.pool.get('account.move')
move_line_obj = self.pool.get('account.move.line')
data_obj = self.pool.get('ir.model.data')
res = self.read(cr, uid, ids[0], ['new_price'])
new_price = res.get('new_price',[])
data = prod_obj.browse(cr, uid, rec_id)
diff = data.standard_price - new_price
prod_obj.write(cr, uid, rec_id, {'standard_price': new_price})
loc_ids = location_obj.search(cr, uid, [('account_id','<>',False),('usage','=','internal')])
lot_ids = lot_obj.search(cr, uid, [('location_id', 'in', loc_ids),('product_id','=',rec_id)])
qty = 0
debit = 0.0
credit = 0.0
stock_input_acc = data.property_stock_account_input.id or data.categ_id.property_stock_account_input_categ.id
stock_output_acc = data.property_stock_account_output.id or data.categ_id.property_stock_account_output_categ.id
for lots in lot_obj.browse(cr, uid, lot_ids):
qty += lots.name
if stock_input_acc and stock_output_acc and lot_ids:
move_id = move_obj.create(cr, uid, {'journal_id': data.categ_id.property_stock_journal.id})
if diff > 0:
credit = qty * diff
move_line_obj.create(cr, uid, {
'name': data.name,
'account_id': stock_input_acc,
'credit': credit,
'move_id': move_id
})
for lots in lot_obj.browse(cr, uid, lot_ids):
credit = lots.name * diff
move_line_obj.create(cr, uid, {
'name': 'Expense',
'account_id': lots.location_id.account_id.id,
'debit': credit,
'move_id': move_id
})
elif diff < 0:
debit = qty * -diff
move_line_obj.create(cr, uid, {
'name': data.name,
'account_id': stock_output_acc,
'debit': debit,
'move_id': move_id
})
for lots in lot_obj.browse(cr, uid, lot_ids):
debit = lots.name * -diff
move_line_obj.create(cr, uid, {
'name': 'Income',
'account_id': lots.location_id.account_id.id,
'credit': debit,
'move_id': move_id
})
else:
raise osv.except_osv(_('Warning!'),_('No Change in Price.'))
else:
raise osv.except_osv(_('Warning!'),_('No Accounts are defined for '
'this product on its location.\nCan\'t create Move.'))
id2 = data_obj._get_id(cr, uid, 'account', 'view_move_tree')
id3 = data_obj._get_id(cr, uid, 'account', 'view_move_form')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
return {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.move',
'res_id' : move_id,
'views': [(id3,'form'),(id2,'tree')],
'type': 'ir.actions.act_window',
}
change_standard_price()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_change_standard_price" model="ir.ui.view">
<field name="name">Change Standard Price</field>
<field name="model">stock.change.standard.price</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Change Standard Price">
<field name="new_price"/>
<newline/>
<group col="2" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="change_price" string="Change" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_view_change_standard_price" model="ir.actions.act_window">
<field name="name">Change Standard Price</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.change.standard.price</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_change_standard_price"/>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -39,7 +39,7 @@ class stock_fill_inventory(osv.osv_memory):
def fill_inventory(self, cr, uid, ids, context):
"""
@summary: To fill stock inventory according to products available in the selected locations..
To fill stock inventory according to products available in the selected locations..
@param self: The object pointer.
@param cr: A database cursor

View File

@ -36,7 +36,7 @@ class stock_inventory_line_split(osv.osv_memory):
def default_get(self, cr, uid, fields, context):
"""
@summary: To get default values for the object.
To check the availability of production lot.
@param self: The object pointer.
@param cr: A database cursor
@ -61,7 +61,7 @@ class stock_inventory_line_split(osv.osv_memory):
def split(self, cr, uid, ids, line_ids, context=None):
"""
@summary:To split Inventory lines into production lot
To split stock inventory lines according to production lot
@param self: The object pointer.
@param cr: A database cursor

View File

@ -38,7 +38,7 @@ class inventory_set_stock_zero(osv.osv_memory):
def do_merge(self, cr, uid, ids, context):
"""
@summary:To set stock to Zero
To set stock to Zero
@param self: The object pointer.
@param cr: A database cursor

View File

@ -43,7 +43,7 @@ class stock_invoice_onshipping(osv.osv_memory):
def _get_type(self, cr, uid, context):
"""
@summary:To get invoice type
To get invoice type
@param self: The object pointer.
@param cr: A database cursor
@ -82,7 +82,7 @@ class stock_invoice_onshipping(osv.osv_memory):
def create_invoice(self, cr, uid, ids, context):
"""
@summary:To create invoice
To create invoice
@param self: The object pointer.
@param cr: A database cursor

View File

@ -31,7 +31,7 @@ class stock_location_product(osv.osv_memory):
def action_open_window(self, cr, uid, ids, context):
"""
@summary:To open location wise product information specific to given duration
To open location wise product information specific to given duration
@param self: The object pointer.
@param cr: A database cursor

View File

@ -37,7 +37,7 @@ class stock_move_track(osv.osv_memory):
def track_lines(self, cr, uid, ids, context={}):
"""
@summary:To track stock moves lines
To track stock moves lines
@param self: The object pointer.
@param cr: A database cursor
@ -90,7 +90,7 @@ class stock_move_consume(osv.osv_memory):
def do_move_consume(self, cr, uid, ids, context={}):
"""
@summary:To move consumed products
To move consumed products
@param self: The object pointer.
@param cr: A database cursor
@ -123,7 +123,7 @@ class stock_move_scrap(osv.osv_memory):
def move_scrap(self, cr, uid, ids, context={}):
"""
@summary:To move scraped products
To move scraped products
@param self: The object pointer.
@param cr: A database cursor
@ -164,7 +164,7 @@ class split_in_production_lot(osv.osv_memory):
def split_lot(self, cr, uid, ids, context=None):
"""
@summary:To split a lot
To split a lot
@param self: The object pointer.
@param cr: A database cursor
@ -180,7 +180,7 @@ class split_in_production_lot(osv.osv_memory):
def split(self, cr, uid, ids, move_ids, context=None):
"""
@summary:To split stock moves into production lot
To split stock moves into production lot
@param self: The object pointer.
@param cr: A database cursor