1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields,osv
24 class stock_location_path(osv.osv):
25 _name = "stock.location.path"
26 _description = "Pushed Flows"
28 'name': fields.char('Operation', size=64),
29 'company_id': fields.many2one('res.company', 'Company'),
30 'product_id' : fields.many2one('product.product', 'Products', ondelete='cascade', select=1),
31 'journal_id': fields.many2one('stock.journal','Journal'),
32 'location_from_id' : fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True),
33 'location_dest_id' : fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True),
34 'delay': fields.integer('Delay (days)', help="Number of days to do this transition"),
35 'invoice_state': fields.selection([
36 ("invoiced", "Invoiced"),
37 ("2binvoiced", "To Be Invoiced"),
38 ("none", "Not Applicable")], "Invoice Status",
40 'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
41 'auto': fields.selection(
42 [('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')],
44 required=True, select=1,
45 help="This is used to define paths the product has to follow within the location tree.\n" \
46 "The 'Automatic Move' value will create a stock move after the current one that will be "\
47 "validated automatically. With 'Manual Operation', the stock move has to be validated "\
48 "by a worker. With 'Automatic No Step Added', the location is replaced in the original move."
54 'invoice_state': 'none',
55 'picking_type': 'internal',
58 class product_pulled_flow(osv.osv):
59 _name = 'product.pulled.flow'
60 _description = "Pulled Flows"
62 'name': fields.char('Name', size=64, required=True, help="This field will fill the packing Origin and the name of its moves"),
63 'cancel_cascade': fields.boolean('Cancel Cascade', help="Allow you to cancel moves related to the product pull flow"),
64 'location_id': fields.many2one('stock.location','Destination Location', required=True, help="Is the destination location that needs supplying"),
65 'location_src_id': fields.many2one('stock.location','Source Location', help="Location used by Destination Location to supply"),
66 'journal_id': fields.many2one('stock.journal','Journal'),
67 'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')], 'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
68 'type_proc': fields.selection([('produce','Produce'),('buy','Buy'),('move','Move')], 'Type of Procurement', required=True),
69 'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company the pickings and moves belong."),
70 'partner_address_id': fields.many2one('res.partner', 'Partner Address'),
71 'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
72 'product_id':fields.many2one('product.product','Product'),
73 'invoice_state': fields.selection([
74 ("invoiced", "Invoiced"),
75 ("2binvoiced", "To Be Invoiced"),
76 ("none", "Not Applicable")], "Invoice Status",
80 'cancel_cascade': False,
81 'procure_method': 'make_to_stock',
83 'picking_type': 'out',
84 'invoice_state': 'none',
85 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.pulled.flow', context=c),
88 class product_product(osv.osv):
89 _inherit = 'product.product'
91 'flow_pull_ids': fields.one2many('product.pulled.flow', 'product_id', 'Pulled Flows'),
92 'path_ids': fields.one2many('stock.location.path', 'product_id',
94 help="These rules set the right path of the product in the "\
95 "whole location tree.")
98 class stock_move(osv.osv):
99 _inherit = 'stock.move'
101 'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too')
103 def action_cancel(self, cr, uid, ids, context=None):
104 for m in self.browse(cr, uid, ids, context=context):
105 if m.cancel_cascade and m.move_dest_id:
106 self.action_cancel(cr, uid, [m.move_dest_id.id], context=context)
107 res = super(stock_move,self).action_cancel(cr,uid,ids,context)
110 def _prepare_chained_picking(self, cr, uid, picking_name, picking, picking_type, moves_todo, context=None):
111 res = super(stock_move, self)._prepare_chained_picking(cr, uid, picking_name, picking, picking_type, moves_todo, context=context)
112 res.update({'invoice_state': moves_todo[0][1][6] or 'none'})
115 class stock_location(osv.osv):
116 _inherit = 'stock.location'
117 def chained_location_get(self, cr, uid, location, partner=None, product=None, context=None):
119 for path in product.path_ids:
120 if path.location_from_id.id == location.id:
121 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, path.invoice_state
122 return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context)
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: