89
88
_description = 'Batch Recall'
91
'date': fields.datetime('Date', readonly=True),
92
'partner_id':fields.many2one('res.partner.address', 'Partner', readonly=True),
92
93
'product_id':fields.many2one('product.product', 'Product', readonly=True),
94
'product_categ_id':fields.many2one('product.category', 'Product Category', readonly=True),
93
95
'location_id': fields.many2one('stock.location', 'Location', readonly=True),
94
'prodlot_id': fields.many2one('stock.production.lot', 'Batch Number', readonly=True),
96
'prodlot_id': fields.many2one('stock.production.lot', 'Lot', readonly=True),
95
97
'expired_date': fields.date('Expired Date', readonly=True),
98
'company_id': fields.many2one('res.company', 'Company', readonly=True),
96
99
'product_qty':fields.float('Quantity', digits_compute=dp.get_precision('Product UoM'), readonly=True),
100
'value' : fields.float('Total Value', digits_compute=dp.get_precision('Account'), required=True),
101
'state': fields.selection([('draft', 'Draft'), ('waiting', 'Waiting'), ('confirmed', 'Confirmed'), ('assigned', 'Available'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, select=True,
102
help='When the stock move is created it is in the \'Draft\' state.\n After that it is set to \'Confirmed\' state.\n If stock is available state is set to \'Avaiable\'.\n When the picking it done the state is \'Done\'.\
103
\nThe state is \'Waiting\' if the move is waiting for another one.'),
97
104
'location_type': fields.selection([('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production'), ('transit', 'Transit Location for Inter-Companies Transfers')], 'Location Type', required=True),
100
107
def init(self, cr):
101
drop_view_if_exists(cr, 'report_batch_recall')
108
tools.drop_view_if_exists(cr, 'report_batch_recall')
103
CREATE OR REPLACE VIEW report_batch_recall AS (
105
row_number() OVER(ORDER BY rec.product_id,
107
rec.location_id) AS id,
108
rec.product_id AS product_id,
109
rec.prodlot_id AS prodlot_id,
110
rec.expired_date AS expired_date,
111
rec.location_id AS location_id,
112
rec.usage AS location_type,
113
sum(rec.product_qty) AS product_qty
117
m.product_id AS product_id,
118
m.prodlot_id AS prodlot_id,
119
m.expired_date AS expired_date,
120
m.location_dest_id AS location_id,
122
CASE when pt.uom_id = m.product_uom
126
sum(round((((m.product_qty/mu.factor)) * pu.factor)/pu.rounding)*pu.rounding)
131
stock_production_lot lot
132
ON m.prodlot_id = lot.id
135
ON m.picking_id = p.id
138
ON m.product_id = pp.id
141
ON pp.product_tmpl_id = pt.id
147
ON m.product_uom = mu.id
150
ON m.location_dest_id = loc.id
154
loc.usage = 'internal'
166
m.product_id AS product_id,
167
m.prodlot_id AS prodlot_id,
168
m.expired_date AS expired_date,
169
m.location_id AS location_id,
171
CASE when pt.uom_id = m.product_uom
175
-sum(round((((m.product_qty/mu.factor)) * pu.factor)/pu.rounding)*pu.rounding)
180
stock_production_lot lot
181
ON m.prodlot_id = lot.id
184
ON m.picking_id = p.id
187
ON m.product_id = pp.id
190
ON pp.product_tmpl_id = pt.id
196
ON m.product_uom = mu.id
199
ON m.location_id = loc.id
203
loc.usage = 'internal'
215
stock_production_lot lot
216
ON rec.prodlot_id = lot.id
230
def unlink(self, cr, uid, ids, context=None):
231
raise osv.except_osv(_('Error !'), _('You cannot delete any record!'))
110
CREATE OR REPLACE view report_batch_recall AS (
112
min(m.id) as id, m.date as date,
113
m.address_id as partner_id, m.location_id as location_id,
114
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
116
m.expired_date::date,
117
m.state as state, m.prodlot_id as prodlot_id,
118
coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0) as value,
119
CASE when pt.uom_id = m.product_uom
121
coalesce(sum(-m.product_qty)::decimal, 0.0)
123
coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
126
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
127
LEFT JOIN product_product pp ON (m.product_id=pp.id)
128
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
129
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
130
LEFT JOIN product_uom u ON (m.product_uom=u.id)
131
LEFT JOIN stock_location l ON (m.location_id=l.id)
132
WHERE l.usage in ('internal', 'customer')
134
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
135
m.prodlot_id, m.expired_date, m.date, m.state, l.usage, m.company_id,pt.uom_id
138
-m.id as id, m.date as date,
139
m.address_id as partner_id, m.location_dest_id as location_id,
140
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
142
m.expired_date::date,
143
m.state as state, m.prodlot_id as prodlot_id,
144
coalesce(sum(pt.standard_price * m.product_qty )::decimal, 0.0) as value,
145
CASE when pt.uom_id = m.product_uom
147
coalesce(sum(m.product_qty)::decimal, 0.0)
149
coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
152
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
153
LEFT JOIN product_product pp ON (m.product_id=pp.id)
154
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
155
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
156
LEFT JOIN product_uom u ON (m.product_uom=u.id)
157
LEFT JOIN stock_location l ON (m.location_dest_id=l.id)
158
WHERE l.usage in ('internal', 'customer')
160
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
161
m.prodlot_id, m.expired_date, m.date, m.state, l.usage, m.company_id,pt.uom_id
233
166
report_batch_recall()
168
class stock_production_lot(osv.osv):
169
_name = 'stock.production.lot'
170
_inherit = 'stock.production.lot'
172
def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=80):
174
Add the possibility to search a lot with its prefix
176
res = super(stock_production_lot, self).name_search(cr, uid, name, args, operator, context, limit)
185
tab_name = name.split('/')
187
if tab_name and len(tab_name) > 1:
188
obj_name = name.split('/')[1][1:-1]
191
domain.append(('name', '=ilike', '%%%s' %obj_name))
193
domain.append(('prefix', '=ilike', '%%%s' %prefix))
195
ids = self.search(cr, uid, domain)
201
return self.name_get(cr, uid, ids)
203
stock_production_lot()
235
205
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: