[WIP] purchase

bzr revid: qdp-launchpad@openerp.com-20130710101616-roothbi3mw9vijr2
This commit is contained in:
Quentin (OpenERP) 2013-07-10 12:16:16 +02:00
parent 49f88904a9
commit d4383a37e1
5 changed files with 66 additions and 23 deletions

View File

@ -156,8 +156,8 @@ class procurement_order(osv.osv):
def check(self, cr, uid, ids, context=None):
done = []
for procurement in self.browse(cr, uid, ids, context=context or {}):
result = self._check(cr, uid, procurement, context=context or {})
for procurement in self.browse(cr, uid, ids, context=context):
result = self._check(cr, uid, procurement, context=context)
if result:
self.write(cr, uid, [procurement.id], {'state': 'done'}, context=context)
done.append(procurement.id)
@ -167,12 +167,24 @@ class procurement_order(osv.osv):
# Method to overwrite in different procurement modules
#
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
def _run(self, cr, uid, procurement, context=None):
'''This method implements the resolution of the given procurement
:param procurement: browse record
'''
return True
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
#

View File

@ -1021,6 +1021,12 @@ class purchase_order_line(osv.osv):
self.write(cr, uid, ids, {'state': 'confirmed'}, context=context)
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):
_inherit = 'procurement.order'
@ -1028,16 +1034,30 @@ class procurement_order(osv.osv):
'purchase_id': fields.many2one('purchase.order', 'Purchase Order'),
}
def check_buy(self, cr, uid, ids, context=None):
''' return True if the supply method of the mto product is 'buy'
'''
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
for procurement in self.browse(cr, uid, ids, context=context):
if procurement.product_id.supply_method <> 'buy':
return False
return True
def _assign(self, cr, uid, procurement, context=None):
rule = super(procurement_order, self)._assign(cr, uid, procurement, context=context)
if not rule:
#if there isn't any specific procurement.rule defined for the product, we try to directly supply it from a supplier
if procurement.product_id.supply_method == 'buy' and self._check_supplier_info(cr, uid, [procurement.id], context=context):
rule = self.pool.get('procurement.rule').search(cr, uid, [('action', '=', 'buy'), ('location_id', '=', procurement.location_id.id)], context=context)
rule = rule and rule[0] or False
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')
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
for procurement in self.browse(cr, uid, ids, context=context):
@ -1065,14 +1085,13 @@ class procurement_order(osv.osv):
return False
return True
def action_po_assign(self, cr, uid, ids, context=None):
""" This is action which call from workflow to assign purchase order to procurements
@return: True
"""
res = self.make_po(cr, uid, ids, context=context)
res = res.values()
return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
#def action_po_assign(self, cr, uid, ids, context=None):
# """ This is action which call from workflow to assign purchase order to procurements
# @return: True
# """
# res = self.make_po(cr, uid, ids, context=context)
# res = res.values()
# 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):
"""Create the purchase order from the procurement, using

View File

@ -534,7 +534,7 @@
<field name="model">procurement.order</field>
<field name="inherit_id" ref="procurement.procurement_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='close_move']" position="before">
<xpath expr="//field[@name='origin']" position="after">
<field name="purchase_id"/>
</xpath>
</field>

View File

@ -1770,11 +1770,11 @@ class stock_move(osv.osv):
'state': 'draft',
'priority': '1',
'product_qty': 1.0,
'scrapped' : False,
'scrapped': False,
'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'),
'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):

View File

@ -1549,6 +1549,18 @@
src_model="procurement.order"
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. -->
<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"/>