25
25
# along with this program; if not, write to the Free Software
26
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
27
###############################################################################
29
from osv import fields
30
from tools.translate import _
32
class suppliers_assigner(osv.osv_memory):
28
from openerp.osv import fields, osv
29
from openerp.tools.translate import _
33
class suppliers_assigner(osv.TransientModel):
34
35
M321 Customizations to assign suppliers in products
36
37
_name = "suppliers.assigner"
39
'sure': fields.boolean("Sure?", help="Check if are sure"),
40
'are_sure': fields.boolean("Are Sure?", help="Check if really are sure"),
43
def assigner_supplier(self,cr,uid,ids,context=None):
40
'sure': fields.boolean("Sure?", help="Check if are sure"),
41
'are_sure': fields.boolean("Are Sure?", help="Check if really are sure"),
44
def assigner_supplier(self, cr, uid, ids, context=None):
44
45
if context is None:
47
48
purchase_obj = self.pool.get('purchase.order')
48
49
product_obj = self.pool.get('product.template')
49
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
50
company_id = self.pool.get(
51
'res.users').browse(cr, uid, uid).company_id.id
50
52
product_supp_obj = self.pool.get('product.supplierinfo')
51
purchase_ids = purchase_obj.search(cr,uid,[],context=context)
52
wz_brw = self.browse(cr,uid,ids and ids[0],context=context)
53
purchase_ids = purchase_obj.search(cr, uid, [], context=context)
54
wz_brw = self.browse(cr, uid, ids and ids[0], context=context)
53
55
if wz_brw.sure and wz_brw.are_sure:
54
for po in purchase_obj.browse(cr, uid, purchase_ids, context = context):
56
for po in purchase_obj.browse(cr, uid, purchase_ids, context=context):
55
57
partner_id = po.partner_id.id
56
58
for line in po.order_line:
57
59
product_id = line.product_id.product_tmpl_id.id
58
if product_id and not product_supp_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', partner_id)]) :
59
product_obj.write(cr,uid,[product_id],{'seller_ids':[(0,0,{'name': partner_id, 'min_qty': 1.0, 'delay': 1, 'sequence': 10,
60
'product_id': product_id, 'company_id': company_id, 'product_uom': line and line.product_id and line.product_id.uom_id and line.product_id.uom_id.id})]})
60
if product_id and not product_supp_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', partner_id)]):
64
'seller_ids': [(0, 0, {'name': partner_id, 'min_qty': 1.0, 'delay': 1, 'sequence': 10,
65
'product_id': product_id, 'company_id': company_id, 'product_uom': line and line.product_id and line.product_id.uom_id and line.product_id.uom_id.id})]})
62
raise osv.except_osv(_('Processing Error'), _('Must select the 2 options to make sure the operation'))
67
raise osv.except_osv(_('Processing Error'), _(
68
'Must select the 2 options to make sure the operation'))
64
70
return {'type': 'ir.actions.act_window_close'}