~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to m321_customization/wizard/supplier_asigner.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
###############################################################################
28
 
from osv import osv
29
 
from osv import fields
30
 
from tools.translate import _
31
 
 
32
 
class suppliers_assigner(osv.osv_memory):
 
28
from openerp.osv import fields, osv
 
29
from openerp.tools.translate import _
 
30
 
 
31
 
 
32
 
 
33
class suppliers_assigner(osv.TransientModel):
33
34
    """
34
35
    M321 Customizations to assign suppliers in products
35
36
    """
36
37
    _name = "suppliers.assigner"
37
 
    
 
38
 
38
39
    _columns = {
39
 
            'sure': fields.boolean("Sure?", help="Check if are sure"),
40
 
            'are_sure': fields.boolean("Are Sure?", help="Check if really are sure"),
41
 
        }
42
 
    
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"),
 
42
    }
 
43
 
 
44
    def assigner_supplier(self, cr, uid, ids, context=None):
44
45
        if context is None:
45
46
            context = {}
46
 
        
 
47
 
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)]):
 
61
                        product_obj.write(
 
62
                            cr, uid, [
 
63
                                product_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})]})
61
66
        else:
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'))
63
69
 
64
70
        return {'type': 'ir.actions.act_window_close'}
65
71
 
66
 
suppliers_assigner()