[WIP] purchase
bzr revid: qdp-launchpad@openerp.com-20130710101616-roothbi3mw9vijr2
This commit is contained in:
parent
49f88904a9
commit
d4383a37e1
|
@ -156,8 +156,8 @@ class procurement_order(osv.osv):
|
||||||
|
|
||||||
def check(self, cr, uid, ids, context=None):
|
def check(self, cr, uid, ids, context=None):
|
||||||
done = []
|
done = []
|
||||||
for procurement in self.browse(cr, uid, ids, context=context or {}):
|
for procurement in self.browse(cr, uid, ids, context=context):
|
||||||
result = self._check(cr, uid, procurement, context=context or {})
|
result = self._check(cr, uid, procurement, context=context)
|
||||||
if result:
|
if result:
|
||||||
self.write(cr, uid, [procurement.id], {'state': 'done'}, context=context)
|
self.write(cr, uid, [procurement.id], {'state': 'done'}, context=context)
|
||||||
done.append(procurement.id)
|
done.append(procurement.id)
|
||||||
|
@ -167,12 +167,24 @@ class procurement_order(osv.osv):
|
||||||
# Method to overwrite in different procurement modules
|
# Method to overwrite in different procurement modules
|
||||||
#
|
#
|
||||||
def _assign(self, cr, uid, procurement, context=None):
|
def _assign(self, cr, uid, procurement, context=None):
|
||||||
|
'''This method returns a procurement.rule that depicts what to go with the given procurement
|
||||||
|
in order to complete its needs. It returns False if no suiting rule is found.
|
||||||
|
:param procurement: browse record
|
||||||
|
:rtype: int or False
|
||||||
|
'''
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _run(self, cr, uid, procurement, context=None):
|
def _run(self, cr, uid, procurement, context=None):
|
||||||
|
'''This method implements the resolution of the given procurement
|
||||||
|
:param procurement: browse record
|
||||||
|
'''
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _check(self, cr, uid, procurement, context=None):
|
def _check(self, cr, uid, procurement, context=None):
|
||||||
|
'''Returns True if the given procurement is fulfilled, False otherwise
|
||||||
|
:param procurement: browse record
|
||||||
|
:rtype: boolean
|
||||||
|
'''
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -1021,6 +1021,12 @@ class purchase_order_line(osv.osv):
|
||||||
self.write(cr, uid, ids, {'state': 'confirmed'}, context=context)
|
self.write(cr, uid, ids, {'state': 'confirmed'}, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class procurement_rule(osv.osv):
|
||||||
|
_inherit = 'procurement.rule'
|
||||||
|
|
||||||
|
def _get_action(self, cr, uid, context=None):
|
||||||
|
return [('buy', 'Buy')] + super(procurement_rule, self)._get_action(cr, uid, context=context)
|
||||||
|
|
||||||
|
|
||||||
class procurement_order(osv.osv):
|
class procurement_order(osv.osv):
|
||||||
_inherit = 'procurement.order'
|
_inherit = 'procurement.order'
|
||||||
|
@ -1028,16 +1034,30 @@ class procurement_order(osv.osv):
|
||||||
'purchase_id': fields.many2one('purchase.order', 'Purchase Order'),
|
'purchase_id': fields.many2one('purchase.order', 'Purchase Order'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def check_buy(self, cr, uid, ids, context=None):
|
def _assign(self, cr, uid, procurement, context=None):
|
||||||
''' return True if the supply method of the mto product is 'buy'
|
rule = super(procurement_order, self)._assign(cr, uid, procurement, context=context)
|
||||||
'''
|
if not rule:
|
||||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
#if there isn't any specific procurement.rule defined for the product, we try to directly supply it from a supplier
|
||||||
for procurement in self.browse(cr, uid, ids, context=context):
|
if procurement.product_id.supply_method == 'buy' and self._check_supplier_info(cr, uid, [procurement.id], context=context):
|
||||||
if procurement.product_id.supply_method <> 'buy':
|
rule = self.pool.get('procurement.rule').search(cr, uid, [('action', '=', 'buy'), ('location_id', '=', procurement.location_id.id)], context=context)
|
||||||
return False
|
rule = rule and rule[0] or False
|
||||||
return True
|
return rule
|
||||||
|
|
||||||
def check_supplier_info(self, cr, uid, ids, context=None):
|
def _run(self, cr, uid, procurement, context=None):
|
||||||
|
if procurement.rule_id and procurement.rule_id.action == 'buy':
|
||||||
|
#make a purchase order for the procurement
|
||||||
|
return self.make_po(cr, uid, [procurement.id], context=context)
|
||||||
|
return super(procurement_order, self)._run(cr, uid, procurement, context=context)
|
||||||
|
|
||||||
|
def _check(self, cr, uid, procurement, context=None):
|
||||||
|
if procurement.purchase_id and procurement.purchase_id.shipped: # TOCHECK: does it work for several deliveries?
|
||||||
|
return True
|
||||||
|
return super(procurement_order, self)._check(cr, uid, procurement, context=context)
|
||||||
|
|
||||||
|
def _check_supplier_info(self, cr, uid, ids, context=None):
|
||||||
|
''' Check the supplier info field of a product and write an error message on the procurement if needed.
|
||||||
|
Returns True if all needed information is there, False if some configuration mistake is detected.
|
||||||
|
'''
|
||||||
partner_obj = self.pool.get('res.partner')
|
partner_obj = self.pool.get('res.partner')
|
||||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||||
for procurement in self.browse(cr, uid, ids, context=context):
|
for procurement in self.browse(cr, uid, ids, context=context):
|
||||||
|
@ -1065,14 +1085,13 @@ class procurement_order(osv.osv):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
#def action_po_assign(self, cr, uid, ids, context=None):
|
||||||
def action_po_assign(self, cr, uid, ids, context=None):
|
# """ This is action which call from workflow to assign purchase order to procurements
|
||||||
""" This is action which call from workflow to assign purchase order to procurements
|
# @return: True
|
||||||
@return: True
|
# """
|
||||||
"""
|
# res = self.make_po(cr, uid, ids, context=context)
|
||||||
res = self.make_po(cr, uid, ids, context=context)
|
# res = res.values()
|
||||||
res = res.values()
|
# return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
|
||||||
return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
|
|
||||||
|
|
||||||
def create_procurement_purchase_order(self, cr, uid, procurement, po_vals, line_vals, context=None):
|
def create_procurement_purchase_order(self, cr, uid, procurement, po_vals, line_vals, context=None):
|
||||||
"""Create the purchase order from the procurement, using
|
"""Create the purchase order from the procurement, using
|
||||||
|
|
|
@ -534,7 +534,7 @@
|
||||||
<field name="model">procurement.order</field>
|
<field name="model">procurement.order</field>
|
||||||
<field name="inherit_id" ref="procurement.procurement_form_view"/>
|
<field name="inherit_id" ref="procurement.procurement_form_view"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='close_move']" position="before">
|
<xpath expr="//field[@name='origin']" position="after">
|
||||||
<field name="purchase_id"/>
|
<field name="purchase_id"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
@ -1770,11 +1770,11 @@ class stock_move(osv.osv):
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'priority': '1',
|
'priority': '1',
|
||||||
'product_qty': 1.0,
|
'product_qty': 1.0,
|
||||||
'scrapped' : False,
|
'scrapped': False,
|
||||||
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
|
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
|
||||||
'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
'procure_method': 'make_to_order', #TODO: Might need to be changed or supplied
|
'procure_method': 'make_to_stock',
|
||||||
}
|
}
|
||||||
|
|
||||||
def _create_procurement(self, cr, uid, move, context=None):
|
def _create_procurement(self, cr, uid, move, context=None):
|
||||||
|
|
|
@ -1549,6 +1549,18 @@
|
||||||
src_model="procurement.order"
|
src_model="procurement.order"
|
||||||
groups="stock.group_stock_user"/>
|
groups="stock.group_stock_user"/>
|
||||||
|
|
||||||
|
<!-- Procurements -->
|
||||||
|
|
||||||
|
<record id="view_procurement_form_stock_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">procurement.order.form.stock.inherit</field>
|
||||||
|
<field name="model">procurement.order</field>
|
||||||
|
<field name="inherit_id" ref="procurement.procurement_form_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='origin']" position="after">
|
||||||
|
<field name="location_id"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
<!-- Procurements are located in Warehouse menu hierarchy, MRP users should come to Stock application to use it. -->
|
<!-- Procurements are located in Warehouse menu hierarchy, MRP users should come to Stock application to use it. -->
|
||||||
<menuitem id="menu_stock_sched" name="Schedulers" parent="stock.menu_stock_root" sequence="4" groups="stock.group_stock_manager"/>
|
<menuitem id="menu_stock_sched" name="Schedulers" parent="stock.menu_stock_root" sequence="4" groups="stock.group_stock_manager"/>
|
||||||
<menuitem action="procurement.action_compute_schedulers" id="menu_stock_proc_schedulers" parent="menu_stock_sched" sequence="20" groups="stock.group_stock_manager"/>
|
<menuitem action="procurement.action_compute_schedulers" id="menu_stock_proc_schedulers" parent="menu_stock_sched" sequence="20" groups="stock.group_stock_manager"/>
|
||||||
|
|
Loading…
Reference in New Issue