Skip to content

Commit

Permalink
Merge pull request odoo#598 from odoo-dev/master-wmsstaging3-jco
Browse files Browse the repository at this point in the history
ooookay
  • Loading branch information
qdp-odoo committed Jun 20, 2014
2 parents 7be384c + 7f7337e commit 7b32559
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 161 deletions.
4 changes: 2 additions & 2 deletions addons/mrp/mrp_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
<field name="move_lines2" nolabel="1" options="{'reload_on_button': true}">
<tree colors="red:scrapped==True;blue:state == 'draft';black:state in ('confirmed','ready','in_production');gray:state == 'cancel' " string="Consumed Products" editable="bottom">
<field name="product_id" readonly="1"/>
<field name="restrict_lot_id" context="{'product_id': product_id}" groups="stock.group_tracking_lot"/>
<field name="restrict_lot_id" context="{'product_id': product_id}" groups="stock.group_production_lot"/>
<field name="product_qty" readonly="1"/>
<field name="product_uom" readonly="1" string="Unit of Measure" groups="product.group_uom"/>
<field name="state" invisible="1"/>
Expand Down Expand Up @@ -774,7 +774,7 @@
<tree colors="red:scrapped==True;blue:state == 'draft';black:state in('confirmed','ready','in_production');gray:state in('cancel','done') " string="Finished Products">
<field name="product_id" readonly="1"/>
<field name="product_qty" readonly="1"/>
<field name="restrict_lot_id" groups="stock.group_tracking_lot"/>
<field name="restrict_lot_id" groups="stock.group_production_lot"/>
<field name="product_uom" readonly="1" string="Unit of Measure" groups="product.group_uom"/>
<field name="location_dest_id" readonly="1" string="Destination Loc." widget="selection" groups="stock.group_locations"/>
<field name="scrapped" invisible="1"/>
Expand Down
6 changes: 3 additions & 3 deletions addons/mrp/wizard/mrp_product_produce_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<field name="lot_id" domain="[('product_id', '=', product_id)]"
context="{'default_product_id':product_id}"
attrs="{'required': [('track_production', '=', True), ('mode', '=', 'consume_produce')]}"
groups="stock.group_tracking_lot"/>
groups="stock.group_production_lot"/>
</group>
<group string="To Consume">
<field name="consume_lines">
<field name="consume_lines" nolabel="1">
<tree string="Consume Lines" editable="top">
<field name="product_id"/>
<field name="product_qty"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]"
context="{'default_product_id':product_id}"
groups="stock.group_tracking_lot"/>
groups="stock.group_production_lot"/>
</tree>
</field>
</group>
Expand Down
2 changes: 1 addition & 1 deletion addons/mrp/wizard/stock_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<field name="product_qty" class="oe_inline"/>
<field name="product_uom" class="oe_inline" readonly="1" groups="product.group_uom"/>
</div>
<field name="restrict_lot_id" domain="[('product_id','=',product_id)]" groups="stock.group_tracking_lot"
<field name="restrict_lot_id" domain="[('product_id','=',product_id)]" groups="stock.group_production_lot"
context="{'default_product_id': product_id}"/>
<field name="location_id" groups="stock.group_locations"/>
</group>
Expand Down
6 changes: 4 additions & 2 deletions addons/mrp_repair/views/report_mrprepairorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<h2>
<span t-if="o.state != 'draft'">Repair Order N°:</span>
<span t-if="o.state == 'draft'">Repair Quotation N°:</span>
<span t-if="o.state == 'draft'">Repair Quotation N°:</span>
<span t-field="o.name"/>
</h2>

Expand All @@ -41,7 +41,9 @@
</div>
<div class="col-xs-3" groups="stock.group_production_lot">
<strong>Lot Number</strong>
<span t-field="o.prodlot_id.name"/>
<t t-if="o.lot_id">
<span t-field="o.lot_id.name"/>
</t>
</div>
<div t-if="o.guarantee_limit" class="col-xs-3">
<strong>Guarantee Limit:</strong>
Expand Down
14 changes: 10 additions & 4 deletions addons/procurement/procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class procurement_group(osv.osv):
}
_defaults = {
'name': lambda self, cr, uid, c: self.pool.get('ir.sequence').get(cr, uid, 'procurement.group') or '',
'move_type': lambda self, cr, uid, c: 'one'
'move_type': lambda self, cr, uid, c: 'direct'
}

class procurement_rule(osv.osv):
Expand Down Expand Up @@ -267,7 +267,7 @@ def _check(self, cr, uid, procurement, context=None):
#
# Scheduler
#
def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):
def run_scheduler(self, cr, uid, use_new_cursor=False, company_id = False, context=None):
'''
Call the scheduler to check the procurement order. This is intented to be done for all existing companies at
the same time, so we're running all the methods as SUPERUSER to avoid intercompany and access rights issues.
Expand All @@ -288,8 +288,11 @@ def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):
cr = openerp.registry(cr.dbname).cursor()

# Run confirmed procurements
dom = [('state', '=', 'confirmed')]
if company_id:
dom += [('company_id', '=', company_id)]
while True:
ids = self.search(cr, SUPERUSER_ID, [('state', '=', 'confirmed')], context=context)
ids = self.search(cr, SUPERUSER_ID, dom, context=context)
if not ids:
break
self.run(cr, SUPERUSER_ID, ids, context=context)
Expand All @@ -298,8 +301,11 @@ def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):

# Check if running procurements are done
offset = 0
dom = [('state', '=', 'running')]
if company_id:
dom += [('company_id', '=', company_id)]
while True:
ids = self.search(cr, SUPERUSER_ID, [('state', '=', 'running')], offset=offset, context=context)
ids = self.search(cr, SUPERUSER_ID, dom, offset=offset, context=context)
if not ids:
break
done = self.check(cr, SUPERUSER_ID, ids, context=context)
Expand Down
6 changes: 5 additions & 1 deletion addons/procurement/wizard/schedulers_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ def _procure_calculation_all(self, cr, uid, ids, context=None):
"""
proc_obj = self.pool.get('procurement.order')
#As this function is in a new thread, i need to open a new cursor, because the old one may be closed

new_cr = self.pool.cursor()
proc_obj.run_scheduler(new_cr, uid, use_new_cursor=new_cr.dbname, context=context)
user = self.pool.get('res.users').browse(new_cr, uid, uid, context=context)
comps = [x.id for x in user.company_ids]
for comp in comps:
proc_obj.run_scheduler(new_cr, uid, use_new_cursor=new_cr.dbname, company_id = comp, context=context)
#close the new cursor
new_cr.close()
return {}
Expand Down
2 changes: 1 addition & 1 deletion addons/product_expiry/product_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_quants(self, cr, uid, ids, context=None):

def apply_removal_strategy(self, cr, uid, location, product, qty, domain, removal_strategy, context=None):
if removal_strategy == 'fefo':
order = 'removal_date, id'
order = 'removal_date, in_date, id'
return self._quants_get_order(cr, uid, location, product, qty, domain, order, context=context)
return super(stock_quant, self).apply_removal_strategy(cr, uid, location, product, qty, domain, removal_strategy, context=context)

Expand Down
30 changes: 19 additions & 11 deletions addons/purchase/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, group
'origin': order.name,
'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [],
'warehouse_id':order.picking_type_id.warehouse_id.id,
'invoice_state': order.invoice_method == 'picking' and '2binvoiced' or 'none'
}

diff_quantity = order_line.product_qty
Expand All @@ -709,9 +710,10 @@ def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, group
tmp.update({
'product_uom_qty': min(procurement_qty, diff_quantity),
'product_uos_qty': min(procurement_qty, diff_quantity),
'move_dest_id': procurement.move_dest_id.id, # blabla
'group_id': procurement.group_id.id or group_id, # blabla to check ca devrait etre bon et groupé dans le meme picking qd meme
'move_dest_id': procurement.move_dest_id.id, #move destination is same as procurement destination
'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group
'procurement_id': procurement.id,
'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state) or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
})
diff_quantity -= min(procurement_qty, diff_quantity)
res.append(tmp)
Expand Down Expand Up @@ -1299,13 +1301,18 @@ def make_po(self, cr, uid, ids, context=None):
res[procurement.id] = False
else:
schedule_date = self._get_purchase_schedule_date(cr, uid, procurement, company, context=context)
purchase_date = self._get_purchase_order_date(cr, uid, procurement, company, schedule_date, context=context)
line_vals = self._get_po_line_values_from_proc(cr, uid, procurement, partner, company, schedule_date, context=context)
#look for any other draft PO for the same supplier, to attach the new line on instead of creating a new draft one
available_draft_po_ids = po_obj.search(cr, uid, [
('partner_id', '=', partner.id), ('state', '=', 'draft'), ('picking_type_id', '=', procurement.rule_id.picking_type_id.id),
('location_id', '=', procurement.location_id.id), ('company_id', '=', procurement.company_id.id), ('dest_address_id', '=', procurement.partner_dest_id.id)], context=context)
if available_draft_po_ids:
po_id = available_draft_po_ids[0]
po_rec = po_obj.browse(cr, uid, po_id, context=context)
#if the product has to be ordered earlier those in the existing PO, we replace the purchase date on the order to avoid ordering it too late
if datetime.strptime(po_rec.date_order, DEFAULT_SERVER_DATE_FORMAT) > purchase_date:
po_obj.write(cr, uid, [po_id], {'date_order': purchase_date}, context=context)
#look for any other PO line in the selected PO with same product and UoM to sum quantities instead of creating a new po line
available_po_line_ids = po_line_obj.search(cr, uid, [('order_id', '=', po_id), ('product_id', '=', line_vals['product_id']), ('product_uom', '=', line_vals['product_uom'])], context=context)
if available_po_line_ids:
Expand All @@ -1318,7 +1325,6 @@ def make_po(self, cr, uid, ids, context=None):
po_line_id = po_line_obj.create(cr, SUPERUSER_ID, line_vals, context=context)
linked_po_ids.append(procurement.id)
else:
purchase_date = self._get_purchase_order_date(cr, uid, procurement, company, schedule_date, context=context)
name = seq_obj.get(cr, uid, 'purchase.order') or _('PO: %s') % procurement.name
po_vals = {
'name': name,
Expand Down Expand Up @@ -1363,6 +1369,13 @@ class product_template(osv.Model):
_name = 'product.template'
_inherit = 'product.template'

def _get_buy_route(self, cr, uid, context=None):

buy_route = self.pool.get('ir.model.data').xmlid_to_res_id(cr, uid, 'purchase.route_warehouse0_buy')
if buy_route:
return [buy_route]
return []

def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, 0)
for template in self.browse(cr, uid, ids, context=context):
Expand All @@ -1374,6 +1387,7 @@ def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
}
_defaults = {
'purchase_ok': 1,
'route_ids': _get_buy_route,
}

class product_product(osv.Model):
Expand Down Expand Up @@ -1451,15 +1465,9 @@ class account_invoice_line(osv.Model):
readonly=True),
}

class product_product(osv.osv):
_inherit = "product.product"
class product_template(osv.osv):
_inherit = "product.template"

def _get_buy_route(self, cr, uid, context=None):
buy_route = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'purchase', 'route_warehouse0_buy')[1]
return [buy_route]

_defaults = {
'route_ids': _get_buy_route,
}

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
27 changes: 27 additions & 0 deletions addons/purchase/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ def copy(self, cr, uid, id, default=None, context=None):
})
return super(stock_move, self).copy(cr, uid, id, default, context)


def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
if move.purchase_line_id:
purchase_line = move.purchase_line_id
self.pool.get('purchase.order.line').write(cr, uid, [purchase_line.id], {
'invoice_lines': [(4, invoice_line_id)]
}, context=context)
self.pool.get('purchase.order').write(cr, uid, [purchase_line.order_id.id], {
'invoice_ids': [(4, invoice_line_vals['invoice_id'])],
})
return invoice_line_id

def _get_master_data(self, cr, uid, move, company, context=None):
if move.purchase_line_id:
purchase_order = move.purchase_line_id.order_id
return purchase_order.partner_id, purchase_order.create_uid.id, purchase_order.pricelist_id.currency_id.id
return super(stock_move, self)._get_master_data(cr, uid, move, company, context=context)

def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
res = super(stock_move, self)._get_invoice_line_vals(cr, uid, move, partner, inv_type, context=context)
if move.purchase_line_id:
purchase_line = move.purchase_line_id
res['invoice_line_tax_id'] = [(6, 0, [x.id for x in purchase_line.taxes_id])]
res['price_unit'] = purchase_line.price_unit
return res

class stock_picking(osv.osv):
_inherit = 'stock.picking'

Expand Down
2 changes: 1 addition & 1 deletion addons/sale_stock/sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def action_cancel(self, cr, uid, ids, context=None):
return super(stock_move, self).action_cancel(cr, uid, ids, context=context)

def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, invoice_line_vals, context=context)
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
if move.procurement_id and move.procurement_id.sale_line_id:
sale_line = move.procurement_id.sale_line_id
self.pool.get('sale.order.line').write(cr, uid, [sale_line.id], {
Expand Down
12 changes: 6 additions & 6 deletions addons/stock/procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def do_view_pickings(self, cr, uid, ids, context=None):
result['domain'] = "[('group_id','in',[" + ','.join(map(str, list(group_ids))) + "])]"
return result

def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):
def run_scheduler(self, cr, uid, use_new_cursor=False, company_id=False, context=None):
'''
Call the scheduler in order to check the running procurements (super method), to check the minimum stock rules
and the availability of moves. This function is intended to be run for all the companies at the same time, so
Expand All @@ -286,8 +286,7 @@ def run_scheduler(self, cr, uid, use_new_cursor=False, context=None):
move_obj = self.pool.get('stock.move')

#Minimum stock rules
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=False, company_id=company.id, context=context)
self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=False, company_id=company_id, context=context)

#Search all confirmed stock_moves and try to assign them
confirmed_ids = move_obj.search(cr, uid, [('state', '=', 'confirmed')], limit=None, order='priority desc, date_expected asc', context=context)
Expand Down Expand Up @@ -331,7 +330,7 @@ def _product_virtual_get(self, cr, uid, order_point):
[order_point.product_id.id],
context={'location': order_point.location_id.id})[order_point.product_id.id]['virtual_available']

def _procure_orderpoint_confirm(self, cr, uid, use_new_cursor=False, company_id=False, context=None):
def _procure_orderpoint_confirm(self, cr, uid, use_new_cursor=False, company_id = False, context=None):
'''
Create procurement based on Orderpoint
Expand All @@ -341,14 +340,15 @@ def _procure_orderpoint_confirm(self, cr, uid, use_new_cursor=False, company_id=
if context is None:
context = {}
if use_new_cursor:
cr = openerp.registry(cr.dbname).db.cursor()
cr = openerp.registry(cr.dbname).cursor()
orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')

procurement_obj = self.pool.get('procurement.order')
offset = 0
ids = [1]
dom = company_id and [('company_id', '=', company_id)] or []
while ids:
ids = orderpoint_obj.search(cr, uid, [('company_id', '=', company_id)], offset=offset, limit=100)
ids = orderpoint_obj.search(cr, uid, dom, offset=offset, limit=100)
for op in orderpoint_obj.browse(cr, uid, ids, context=context):
prods = self._product_virtual_get(cr, uid, op)
if prods is None:
Expand Down
Loading

0 comments on commit 7b32559

Please sign in to comment.