Esempio n. 1
0
class sale_order_line(models.Model):
    _inherit = 'sale.order.line'
    _description = 'Sales Order Line'

    brand = fields.many2one(
        'brand.brand', 'Brand', related="product_id.brand"
    )  #TODO Verificar sinntaxis de campo reñlated en ODOO 11
Esempio n. 2
0
class account_voucher_line(osv.osv):
    _inherit= 'account.voucher.line'
    _columns={
        'event_date': fields.date('Date Of Service'),
        'patient_id': fields.many2one('patient', 'Patient/Client',),
        'reference': fields.char('Reference', size=64, select=1),
        'project_name_id':fields.many2one('project','Project'),
    }
    
    def default_get(self, cr, user, fields_list, context=None):
        vals = super(account_voucher_line, self).default_get(cr, user, fields_list,context=context)
        vals.update({
            'account_id':'',
            'type':''
        })
        return vals
Esempio n. 3
0
class ir_mail_server(osv.osv):
    _inherit = 'ir.mail_server'

    _columns = {
        'user_id': fields.many2one('res.users', string='Owner'),
    }

    _sql_constraints = [
        ('smtp_user_uniq', 'unique(user_id)',
         'That user already has a SMTP server.'),
    ]
Esempio n. 4
0
class Souche(models.Model):
    _name = 'souchier.souche'
    
    name = fields.Char(string="Souche", required=True, index=True)
    description = fields.Text(string="Description")
    _sql_constraints = [('name', 'unique(name)',
                         "Le nom de la souche doit etre unique")]
    client = fields.many2one(comodel_name='res.users', string="Client",
                             required=True, ondelete='restrict')
    emplacement = fields.many2one(comodel_name='souchier.emplacement',
                                  string="Emplacement master",
                                  ondelete="restrict",
                                  required=True)

    emplacements_WS = fields.one2many(comodel_name='souchier.emplacement',
                                       string="Emplacements working seeds",
                                       ondelete='restrict',
                                      inverse_name='occupe_par',
                                       required=False)
    date_reception = fields.Date(required=True)
    
                        
Esempio n. 5
0
class res_partner_working_time(models.Model):
    _name = "res.partner.working.time"
    _columns = {
        'partner_id':
        fields.many2one(
            'res.partner',
            'Partner',
            ondelete='cascade',
            select=True,
            domain=['|', ('is_company', '=', True),
                    ('parent_id', '=', False)]),
        'days':
        fields.char('Days'),
        'morning':
        fields.char('Morning'),
        'afternoon':
        fields.char('Afternoon'),
    }
Esempio n. 6
0
class HrChildren(model.Model):
    """Class to add object of childrens to employee
    """
    _name = "hr.children"

    _order = 'name'

    _columns = {
        'name':
        fields.char('Name', size=64, required=True),
        'date_of_birth':
        fields.date('Date of birth'),
        'schooling':
        fields.selection([('elementary', 'Elementary'),
                          ('high_school', 'High School'),
                          ('preparatory', 'Preparatory'),
                          ('university', 'University')], 'Schooling'),
        'employee_id':
        fields.many2one('hr.employee', 'Employee')
    }
Esempio n. 7
0
class WebsiteProposal(models.Model):
    _name = 'website_proposal.proposal'
    _rec_name = 'id'

    def _get_default_company(self):
        company_id = self.env['res.users']._get_company(context=context)
        if not company_id:
            raise UserError(_('Error!'), _('There is no default company for the current user!'))
        return company_id

    def _get_res_name(self, name, args):
        res = {}
        for r in self.browse(ids):
            record = self.env[r.res_model].browse(r.res_id)
            res[r.id] = record.name
        return res

    _columns = {
        'res_name': fields.function(_get_res_name, string='Name', type='char'),
        'access_token': fields.char('Security Token', required=True, copy=False),
        'template_id': fields.many2one('website_proposal.template', 'Quote Template', readonly=True),
        'head': fields.text('Html head'),
        'page_header': fields.text('Page header'),
        'website_description': fields.html('Description'),
        'page_footer': fields.text('Page footer'),

        'res_model': fields.char('Model', readonly=True, help="The database object this is attached to"),
        'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to", select=True),
        'sign': fields.binary('Singature'),
        'sign_date': fields.datetime('Signing Date'),
        'signer': fields.binary('Signer'),
        'state': fields.selection([
            ('draft', 'Draft'),
            ('rejected', 'Rejected'),
            ('done', 'Signed'),
        ]),
        'company_id': fields.many2one('res.company', 'Company'),
    }
    _defaults = {
        'access_token': lambda self, cr, uid, ctx={}: str(uuid.uuid4()),
        'company_id': _get_default_company,
        'state': 'draft',
    }

    def open_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s' % (ids[0])
        }

    def edit_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s?enable_editor' % (ids[0])
        }

    def create(self, vals):
        record = self.env[vals.get('res_model']).browse(vals.get('res_id'))

        mako = mako_template_env.from_string(tools.ustr(vals.get('website_description')))
        website_description = mako.render({'record': record})
        website_description = website_description.replace('template-only-', '')

        vals['website_description'] = website_description
        new_id = super(WebsiteProposal, self).create(vals)
        return new_id
Esempio n. 8
0
class account_fiscalyear_close(osv.osv_memory):
    """
    Closes Account Fiscalyear and Generate Opening entries for New Fiscalyear
    """
    _name = "account.fiscalyear.close"
    _description = "Fiscalyear Close"
    _columns = {
        'fy_id':
        fields.many2one('account.fiscalyear',
                        'Fiscal Year to close',
                        required=True,
                        help="Select a Fiscal year to close"),
        'fy2_id':
        fields.many2one('account.fiscalyear', 'New Fiscal Year',
                        required=True),
        'journal_id':
        fields.many2one(
            'account.journal',
            'Opening Entries Journal',
            domain="[('type','=','situation')]",
            required=True,
            help=
            'The best practice here is to use a journal dedicated to contain the opening entries of all fiscal years. Note that you should define it with default debit/credit accounts, of type \'situation\' and with a centralized counterpart.'
        ),
        'period_id':
        fields.many2one('account.period',
                        'Opening Entries Period',
                        required=True),
        'report_name':
        fields.char('Name of new entries',
                    required=True,
                    help="Give name of the new entries"),
    }
    _defaults = {
        'report_name':
        lambda self, cr, uid, context: _('End of Fiscal Year Entry'),
    }

    def data_save(self, cr, uid, ids, context=None):
        """
        This function close account fiscalyear and create entries in new fiscalyear
        @param cr: the current row, from the database cursor,
        @param uid: the current user’s ID for security checks,
        @param ids: List of Account fiscalyear close state’s IDs

        """
        def _reconcile_fy_closing(cr, uid, ids, context=None):
            """
            This private function manually do the reconciliation on the account_move_line given as `ids´, and directly
            through psql. It's necessary to do it this way because the usual `reconcile()´ function on account.move.line
            object is really resource greedy (not supposed to work on reconciliation between thousands of records) and
            it does a lot of different computation that are useless in this particular case.
            """
            # check that the reconcilation concern journal entries from only one company
            cr.execute(
                'select distinct(company_id) from account_move_line where id in %s',
                (tuple(ids), ))
            if len(cr.fetchall()) > 1:
                raise osv.except_osv(
                    _('Warning!'),
                    _('The entries to reconcile should belong to the same company.'
                      ))
            r_id = self.pool.get('account.move.reconcile').create(
                cr, uid, {
                    'type': 'auto',
                    'opening_reconciliation': True
                })
            cr.execute(
                'update account_move_line set reconcile_id = %s where id in %s',
                (
                    r_id,
                    tuple(ids),
                ))
            # reconcile_ref deptends from reconcile_id but was not recomputed
            obj_acc_move_line._store_set_values(cr,
                                                uid,
                                                ids, ['reconcile_ref'],
                                                context=context)
            obj_acc_move_line.invalidate_cache(cr,
                                               uid, ['reconcile_id'],
                                               ids,
                                               context=context)
            return r_id

        obj_acc_period = self.pool.get('account.period')
        obj_acc_fiscalyear = self.pool.get('account.fiscalyear')
        obj_acc_journal = self.pool.get('account.journal')
        obj_acc_move = self.pool.get('account.move')
        obj_acc_move_line = self.pool.get('account.move.line')
        obj_acc_account = self.pool.get('account.account')
        obj_acc_journal_period = self.pool.get('account.journal.period')
        currency_obj = self.pool.get('res.currency')

        data = self.browse(cr, uid, ids, context=context)

        if context is None:
            context = {}
        fy_id = data[0].fy_id.id

        cr.execute(
            "SELECT id FROM account_period WHERE date_stop < (SELECT date_start FROM account_fiscalyear WHERE id = %s)",
            (str(data[0].fy2_id.id), ))
        fy_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall()))
        cr.execute(
            "SELECT id FROM account_period WHERE date_start > (SELECT date_stop FROM account_fiscalyear WHERE id = %s)",
            (str(fy_id), ))
        fy2_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall()))

        if not fy_period_set or not fy2_period_set:
            raise osv.except_osv(
                _('User Error!'),
                _('The periods to generate opening entries cannot be found.'))

        period = obj_acc_period.browse(cr,
                                       uid,
                                       data[0].period_id.id,
                                       context=context)
        new_fyear = obj_acc_fiscalyear.browse(cr,
                                              uid,
                                              data[0].fy2_id.id,
                                              context=context)
        old_fyear = obj_acc_fiscalyear.browse(cr, uid, fy_id, context=context)

        new_journal = data[0].journal_id.id
        new_journal = obj_acc_journal.browse(cr,
                                             uid,
                                             new_journal,
                                             context=context)
        company_id = new_journal.company_id.id

        if not new_journal.default_credit_account_id or not new_journal.default_debit_account_id:
            raise osv.except_osv(
                _('User Error!'),
                _('The journal must have default credit and debit account.'))
        if (not new_journal.centralisation) or new_journal.entry_posted:
            raise osv.except_osv(
                _('User Error!'),
                _('The journal must have centralized counterpart without the Skipping draft state option checked.'
                  ))

        # delete existing move and move lines if any
        move_ids = obj_acc_move.search(cr, uid,
                                       [('journal_id', '=', new_journal.id),
                                        ('period_id', '=', period.id)])
        if move_ids:
            move_line_ids = obj_acc_move_line.search(
                cr, uid, [('move_id', 'in', move_ids)])
            obj_acc_move_line._remove_move_reconcile(
                cr,
                uid,
                move_line_ids,
                opening_reconciliation=True,
                context=context)
            obj_acc_move_line.unlink(cr, uid, move_line_ids, context=context)
            obj_acc_move.unlink(cr, uid, move_ids, context=context)

        cr.execute("SELECT id FROM account_fiscalyear WHERE date_stop < %s",
                   (str(new_fyear.date_start), ))
        result = cr.dictfetchall()
        fy_ids = [x['id'] for x in result]
        query_line = obj_acc_move_line._query_get(
            cr, uid, obj='account_move_line', context={'fiscalyear': fy_ids})
        # create the opening move
        vals = {
            'name': '/',
            'ref': '',
            'period_id': period.id,
            'date': period.date_start,
            'journal_id': new_journal.id,
        }
        move_id = obj_acc_move.create(cr, uid, vals, context=context)

        # 1. report of the accounts with defferal method == 'unreconciled'
        cr.execute(
            '''
            SELECT a.id
            FROM account_account a
            LEFT JOIN account_account_type t ON (a.user_type_id = t.id)
            WHERE a.active
              AND a.type not in ('view', 'consolidation')
              AND a.company_id = %s
              AND t.close_method = %s''', (
                company_id,
                'unreconciled',
            ))
        account_ids = map(lambda x: x[0], cr.fetchall())
        if account_ids:
            cr.execute(
                '''
                INSERT INTO account_move_line (
                     name, create_uid, create_date, write_uid, write_date,
                     statement_id, journal_id, currency_id, date_maturity,
                     partner_id, blocked, credit, state, debit,
                     ref, account_id, period_id, date, move_id, amount_currency,
                     quantity, product_id, company_id)
                  (SELECT name, create_uid, create_date, write_uid, write_date,
                     statement_id, %s,currency_id, date_maturity, partner_id,
                     blocked, credit, 'draft', debit, ref, account_id,
                     %s, (%s) AS date, %s, amount_currency, quantity, product_id, company_id
                   FROM account_move_line
                   WHERE account_id IN %s
                     AND ''' + query_line + '''
                     AND reconcile_id IS NULL)''', (
                    new_journal.id,
                    period.id,
                    period.date_start,
                    move_id,
                    tuple(account_ids),
                ))

            # We have also to consider all move_lines that were reconciled
            # on another fiscal year, and report them too
            cr.execute(
                '''
                INSERT INTO account_move_line (
                     name, create_uid, create_date, write_uid, write_date,
                     statement_id, journal_id, currency_id, date_maturity,
                     partner_id, blocked, credit, state, debit,
                     ref, account_id, period_id, date, move_id, amount_currency,
                     quantity, product_id, company_id)
                  (SELECT
                     b.name, b.create_uid, b.create_date, b.write_uid, b.write_date,
                     b.statement_id, %s, b.currency_id, b.date_maturity,
                     b.partner_id, b.blocked, b.credit, 'draft', b.debit,
                     b.ref, b.account_id, %s, (%s) AS date, %s, b.amount_currency,
                     b.quantity, b.product_id, b.company_id
                     FROM account_move_line b
                     WHERE b.account_id IN %s
                       AND b.reconcile_id IS NOT NULL
                       AND b.period_id IN (''' + fy_period_set + ''')
                       AND b.reconcile_id IN (SELECT DISTINCT(reconcile_id)
                                          FROM account_move_line a
                                          WHERE a.period_id IN (''' +
                fy2_period_set + ''')))''', (
                    new_journal.id,
                    period.id,
                    period.date_start,
                    move_id,
                    tuple(account_ids),
                ))
            self.invalidate_cache(cr, uid, context=context)

        # 2. report of the accounts with defferal method == 'detail'
        cr.execute(
            '''
            SELECT a.id
            FROM account_account a
            LEFT JOIN account_account_type t ON (a.user_type_id= t.id)
            WHERE a.active
              AND a.type not in ('view', 'consolidation')
              AND a.company_id = %s
              AND t.close_method = %s''', (
                company_id,
                'detail',
            ))
        account_ids = map(lambda x: x[0], cr.fetchall())

        if account_ids:
            cr.execute(
                '''
                INSERT INTO account_move_line (
                     name, create_uid, create_date, write_uid, write_date,
                     statement_id, journal_id, currency_id, date_maturity,
                     partner_id, blocked, credit, state, debit,
                     ref, account_id, period_id, date, move_id, amount_currency,
                     quantity, product_id, company_id)
                  (SELECT name, create_uid, create_date, write_uid, write_date,
                     statement_id, %s,currency_id, date_maturity, partner_id,
                     blocked, credit, 'draft', debit, ref, account_id,
                     %s, (%s) AS date, %s, amount_currency, quantity, product_id, company_id
                   FROM account_move_line
                   WHERE account_id IN %s
                     AND ''' + query_line + ''')
                     ''', (
                    new_journal.id,
                    period.id,
                    period.date_start,
                    move_id,
                    tuple(account_ids),
                ))
            self.invalidate_cache(cr, uid, context=context)

        # 3. report of the accounts with defferal method == 'balance'
        cr.execute(
            '''
            SELECT a.id
            FROM account_account a
            LEFT JOIN account_account_type t ON (a.user_type_id = t.id)
            WHERE a.active
              AND a.type not in ('view', 'consolidation')
              AND a.company_id = %s
              AND t.close_method = %s''', (
                company_id,
                'balance',
            ))
        account_ids = map(lambda x: x[0], cr.fetchall())

        query_1st_part = """
                INSERT INTO account_move_line (
                     debit, credit, name, date, move_id, journal_id, period_id,
                     account_id, currency_id, amount_currency, company_id, state) VALUES
        """
        query_2nd_part = ""
        query_2nd_part_args = []
        for account in obj_acc_account.browse(cr,
                                              uid,
                                              account_ids,
                                              context={'fiscalyear': fy_id}):
            company_currency_id = self.pool.get('res.users').browse(
                cr, uid, uid).company_id.currency_id
            if not currency_obj.is_zero(cr, uid, company_currency_id,
                                        abs(account.balance)):
                if query_2nd_part:
                    query_2nd_part += ','
                query_2nd_part += "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
                query_2nd_part_args += (
                    account.balance > 0 and account.balance
                    or 0.0, account.balance < 0 and -account.balance
                    or 0.0, data[0].report_name, period.date_start, move_id,
                    new_journal.id, period.id, account.id,
                    account.currency_id and account.currency_id.id or None,
                    account.foreign_balance if account.currency_id else 0.0,
                    account.company_id.id, 'draft')
        if query_2nd_part:
            cr.execute(query_1st_part + query_2nd_part,
                       tuple(query_2nd_part_args))
            self.invalidate_cache(cr, uid, context=context)

        # validate and centralize the opening move
        obj_acc_move.validate(cr, uid, [move_id], context=context)

        # reconcile all the move.line of the opening move
        ids = obj_acc_move_line.search(
            cr, uid, [('journal_id', '=', new_journal.id),
                      ('period_id.fiscalyear_id', '=', new_fyear.id)])
        if ids:
            reconcile_id = _reconcile_fy_closing(cr, uid, ids, context=context)
            # set the creation date of the reconcilation at the first day of the new fiscalyear, in order to have good figures in the aged trial balance
            self.pool.get('account.move.reconcile').write(
                cr,
                uid, [reconcile_id], {'create_date': new_fyear.date_start},
                context=context)

        # create the journal.period object and link it to the old fiscalyear
        new_period = data[0].period_id.id
        ids = obj_acc_journal_period.search(
            cr, uid, [('journal_id', '=', new_journal.id),
                      ('period_id', '=', new_period)])
        if not ids:
            ids = [
                obj_acc_journal_period.create(
                    cr, uid, {
                        'name':
                        (new_journal.name or '') + ':' + (period.code or ''),
                        'journal_id':
                        new_journal.id,
                        'period_id':
                        period.id
                    })
            ]
        cr.execute(
            'UPDATE account_fiscalyear '
            'SET end_journal_period_id = %s '
            'WHERE id = %s', (ids[0], old_fyear.id))
        obj_acc_fiscalyear.invalidate_cache(cr,
                                            uid, ['end_journal_period_id'],
                                            [old_fyear.id],
                                            context=context)

        return {'type': 'ir.actions.act_window_close'}
Esempio n. 9
0
class Emplacement(models.Model):
    _name = 'souchier.emplacement'
    name = fields.Char(string="Emplacement", required=True, index=True)
    occupe_par = fields.many2one(comodel_name='souchier.souche', required=False,
                                 , ondelete='set null')
Esempio n. 10
0
class assign_interpreter(osv.osv_memory):
    """ A wizard to assign interpreter to event """
    _name = 'assign.interpreter'

    #    def message_open(self , cr ,uid , ids , context=None):
    #        res = self.pool.get('warning').warning(cr ,uid ,title='Title', message='Text' )
    #        return res
    def update_interpreter(self, cr, uid, ids, context):
        ''' This function updates or assigns interpreter in the event form '''
        res = []
        cur_obj = self.browse(cr, uid, ids[0])

        #        if not interpreter2:
        #            raise osv.except_osv(_('Warning!'),_('You must select an Interpreter to assign to this event.'))
        #print "interpreter.......",interpreter
        event_ids = context.get('active_ids', [])
        #print "event_ids......",event_ids
        if not event_ids:
            return res
        count = 0
        for interp in cur_obj.interpreter_ids:
            if interp.select:
                count += 1
        if count == 0:
            raise osv.except_osv(
                _('Warning!'),
                _('You must select an Interpreter to assign to this event.'))
        if count > 1:
            raise osv.except_osv(
                _('Warning!'),
                _('You can select only one Interpreter to assign to this event.'
                  ))
        for interp in cur_obj.interpreter_ids:
            #print "interp...........",interp
            if interp.select:
                res = self.pool.get('event').write(
                    cr, uid, event_ids, {
                        'interpreter_id':
                        interp.interpreter_id and interp.interpreter_id.id
                        or False,
                        'voicemail_msg':
                        interp.voicemail_msg,
                        'state':
                        'scheduled'
                    })
                return res

        #res = self.pool.get('event').write(cr ,uid ,event_ids , {'interpreter_id':interpreter2.interpreter_id and interpreter2.interpreter_id.id or False,'state':'scheduled'})
        return res

#    def onchange_partner_id(self, cr, uid, ids,  partner_id, context = None):
#
#        for p in self.pool.get('product.product').browse(cr, uid, product_ids):
#            invoice_lines.append((0,0,{'product_id':p.id,'name':p.name,
#                              'account_id':p.categ_id.property_account_income_categ.id,
#                              }))#this dict contain keys which are fields of one2many field
#        res['value']['interpreter_ids']=[(6, 0, tax_ids)]
#        return res

    def default_get(self, cr, uid, fields, context=None):
        print "default_get........"
        #cr.execute('insert into relation_name (self_id,module_name_id) values(%s,%s)',(first_value,second_value)
        res = {}
        if context is None: context = {}
        res = super(assign_interpreter, self).default_get(cr,
                                                          uid,
                                                          fields,
                                                          context=context)
        event_ids = context.get('active_ids', [])
        print "event_ids........", event_ids
        #active_model = context.get('active_model')
        if not event_ids or len(event_ids) != 1:
            # Partial Picking Processing may only be done for one picking at a time
            return res
        event_id, = event_ids
        if 'event_id' in fields:
            res.update(event_id=event_id)
        event = self.pool.get('event').browse(cr,
                                              uid,
                                              event_id,
                                              context=context)
        state = event.state
        if 'language_id' in fields:
            res.update({
                'language_id':
                event.language_id and event.language_id.id or False
            })
        #print "default_get..........",res

        event_ids = context.get('active_ids', [])
        #print "event_ids.......",event_ids
        obj = self.pool.get('hr.employee')
        select_obj = self.pool.get('select.interpreter')
        interpreter_ids = new_ids = select_ids = []
        if event_ids:
            lang = self.pool.get('event').browse(cr, uid,
                                                 event_ids[0]).language_id
            partner = self.pool.get('event').browse(cr, uid,
                                                    event_ids[0]).partner_id
            #            print "lang....",lang
            #            lang = self.browse(cr, uid, ids, context=context)
            #            sql = "select  interpreter_id from interpreter_language where name = %d"%(lang.id)
            int_lang_ids = self.pool.get('interpreter.language').search(
                cr, uid, [('name', '=', lang.id)])
            #            print "int_lang_ids........",int_lang_ids

            if int_lang_ids:
                for int_lang_id in int_lang_ids:
                    lang_browse = self.pool.get('interpreter.language').browse(
                        cr, uid, int_lang_id)
                    interpreter_ids.append(lang_browse.interpreter_id.id)
            new_ids = interpreter_ids
            if interpreter_ids:
                print "interpreter_ids........", interpreter_ids
                zip = partner.zip
                #print "zip...........",zip
                if zip:
                    #                    gibberish = urllib.urlopen('http://www.uszip.com/zip/' + '203150')
                    #                    less_gib = gibberish.read().decode('utf-8')
                    #                    query = "select id from hr_employee where zip = %s and id in %s"%( str(zip) + '' , tuple(interpreter_ids))
                    #                    cr.execute(query )
                    #                    i_ids = map(lambda x: x[0], cr.fetchall())
                    min_zip = int(zip) - 10
                    max_zip = int(zip) + 10
                    print "min_zip...max_zip......", min_zip, max_zip
                    visit_ids = []
                    for history in partner.interpreter_history:
                        if history.name.id in interpreter_ids:
                            visit_ids.append(history.name.id)
                    if visit_ids:
                        visit_ids = flatten(visit_ids)
                        visit_ids = list(set(visit_ids))

                    print "visit_ids........", visit_ids
                    for visit_id in visit_ids:
                        if visit_id in interpreter_ids:
                            interpreter_ids.remove(visit_id)
#                    print "visit_ids........",visit_ids
#                    print "interpreter_ids......",interpreter_ids
                    i_ids = obj.search(cr,
                                       uid,
                                       [('zip', '=', zip),
                                        ('id', 'in', tuple(interpreter_ids))],
                                       order="rate")
                    #                    print "i_ids.......",i_ids
                    #                    i_ids1 = obj.search(cr ,uid ,[('zip','!=',zip),('zip','!=',zip),('zip','!=',zip),('id','in',tuple(interpreter_ids))])
                    #                    query = "select id from hr_employee where zip::integer != %s and zip::integer <= %s and zip::integer >= %s and id in %s  order by rate "%( str(zip), str(max_zip) ,str(min_zip)  , tuple(interpreter_ids))
                    #                    cr.execute(query )
                    #                    i_ids1 = map(lambda x: x[0], cr.fetchall())
                    i_ids1 = obj.search(cr,
                                        uid,
                                        [('zip', '!=', zip),
                                         ('zip', '<=', max_zip),
                                         ('zip', '>=', min_zip),
                                         ('id', 'in', tuple(interpreter_ids))],
                                        order="rate")
                    print "i_ids1.......", i_ids1
                    new_ids = i_ids + i_ids1
                    #                    print "new_ids...........",new_ids
                    #                    select_ids = select_obj.search(cr ,uid ,[])
                    #                    print "select_ids........",select_ids
                    #                    for select_id in select_ids:
                    #                        select_obj.unlink(cr ,uid , select_id)
                    #                    query1 = "delete from select_assign_rel "
                    #                    cr.execute(query1 )
                    select_ids = []
                    for visit_id in visit_ids:
                        query = "select max(event_date) from interpreter_alloc_history where partner_id = %s and name = %s " % (
                            partner.id, visit_id)
                        cr.execute(query)
                        last_visit_date = map(lambda x: x[0], cr.fetchall())
                        #                        print "last_visit_date........",last_visit_date
                        history_ids = self.pool.get(
                            'interpreter.history').search(
                                cr,
                                uid, [(
                                    'name',
                                    '=',
                                    visit_id,
                                ), ('event_id', '=', event_ids[0]),
                                      ('state', '=', 'voicemailsent')],
                                order="event_date desc")
                        #voicemail_msg = self.pool.get('hr.employee').browse(cr ,uid , visit_id).voicemail_msg
                        voicemail_msg = ''
                        if history_ids:
                            voicemail_msg = self.pool.get(
                                'interpreter.history').browse(
                                    cr, uid, history_ids[0]).voicemail_msg
                        if last_visit_date and last_visit_date[0]:
                            select_ids.append(
                                select_obj.create(
                                    cr, uid, {
                                        'interpreter_id': visit_id,
                                        'event_id': event_ids[0],
                                        'visited': True,
                                        'visited_date': last_visit_date,
                                        'state': state,
                                        'voicemail_msg': voicemail_msg
                                    }))
                        else:
                            select_ids.append(
                                select_obj.create(
                                    cr, uid, {
                                        'interpreter_id': visit_id,
                                        'event_id': event_ids[0],
                                        'visited': True,
                                        'state': state,
                                        'voicemail_msg': voicemail_msg
                                    }))
                    for new_id in new_ids:
                        history_ids = self.pool.get(
                            'interpreter.history').search(
                                cr,
                                uid, [(
                                    'name',
                                    '=',
                                    new_id,
                                ), ('event_id', '=', event_ids[0]),
                                      ('state', '=', 'voicemailsent')],
                                order="event_date desc")
                        voicemail_msg = ''
                        if history_ids:
                            voicemail_msg = self.pool.get(
                                'interpreter.history').browse(
                                    cr, uid, history_ids[0]).voicemail_msg
                        select_ids.append(
                            select_obj.create(
                                cr, uid, {
                                    'interpreter_id': new_id,
                                    'event_id': event_ids[0],
                                    'state': state,
                                    'voicemail_msg': voicemail_msg
                                }))
#                    new_ids = tuple(new_ids)
#                    print "new_ids.....",new_ids
#                    print "list(new_ids).....",list(new_ids)
#                    print "select_ids........",select_ids

        res['interpreter_ids'] = select_ids  #[(6, 0, select_ids)]
        return res

    def fields_view_get(self,
                        cr,
                        uid,
                        view_id=None,
                        view_type='form',
                        context=None,
                        toolbar=False,
                        submenu=False):
        print "fields_view_get......."
        if context is None:
            context = {}
        result = super(assign_interpreter,
                       self).fields_view_get(cr, uid, view_id, view_type,
                                             context, toolbar, submenu)
        if 'active_ids' not in context:
            context['active_ids'] = []
#        event_ids = context.get('active_ids', [])
#        print "event_ids.......",event_ids
#        obj = self.pool.get('hr.employee')
#        select_obj = self.pool.get('select.interpreter')
#        interpreter_ids = new_ids = []
        query = "delete from select_interpreter "
        cr.execute(query)
        query = "delete from select_assign_rel "
        cr.execute(query)
        #        if event_ids:
        #            lang = self.pool.get('event').browse(cr ,uid ,event_ids[0]).language_id
        #            partner = self.pool.get('event').browse(cr ,uid ,event_ids[0]).partner_id
        #            print "lang....",lang
        #            lang = self.browse(cr, uid, ids, context=context)
        #            sql = "select  interpreter_id from interpreter_language where name = %d"%(lang.id)
        #            int_lang_ids = self.pool.get('interpreter.language').search(cr ,uid ,[('name','=',lang.id)])
        #            print "int_lang_ids........",int_lang_ids
        #
        #            if int_lang_ids:
        #                for int_lang_id in int_lang_ids:
        #                    lang_browse = self.pool.get('interpreter.language').browse(cr ,uid ,int_lang_id)
        #                    interpreter_ids.append(lang_browse.interpreter_id.id)
        #            new_ids = interpreter_ids
        #            if interpreter_ids:
        #                print "interpreter_ids........",interpreter_ids
        #                zip = partner.zip
        #                print "zip...........",zip
        #                if zip:
        #                    gibberish = urllib.urlopen('http://www.uszip.com/zip/' + '203150')
        #                    less_gib = gibberish.read().decode('utf-8')
        #                    query = "select id from hr_employee where zip = %s and id in %s"%( str(zip) + '' , tuple(interpreter_ids))
        #                    cr.execute(query )
        #                    i_ids = map(lambda x: x[0], cr.fetchall())
        #                    min_zip = int(zip) - 10
        #                    max_zip = int(zip) + 10
        #                    print "min_zip...max_zip......",min_zip,max_zip
        #                    visit_ids = []
        #                    for history in partner.interpreter_history:
        #                        visit_ids.append(history.name.id)
        #                    if visit_ids:
        #                        visit_ids = flatten(visit_ids)
        #                        visit_ids = list(set(visit_ids))
        #                    print "visit_ids........",visit_ids
        #                    for visit_id in visit_ids:
        #                        if visit_id in interpreter_ids:
        #                            interpreter_ids.remove(visit_id)
        #                    print "visit_ids........",visit_ids
        #                    print "interpreter_ids......",interpreter_ids
        #                    i_ids = obj.search(cr ,uid ,[('zip','=',zip),('id','in',tuple(interpreter_ids))] , order ="rate")
        #                    print "i_ids.......",i_ids
        #                    #i_ids1 = obj.search(cr ,uid ,[('zip','!=',zip),('zip','!=',zip),('zip','!=',zip),('id','in',tuple(interpreter_ids))])
        #                    query = "select id from hr_employee where zip::integer != %s and zip::integer <= %s and zip::integer >= %s and id in %s  order by rate "%( str(zip), str(max_zip) ,str(min_zip)  , tuple(interpreter_ids))
        #                    cr.execute(query )
        #                    i_ids1 = map(lambda x: x[0], cr.fetchall())
        #                    print "i_ids1.......",i_ids1
        #                    new_ids = visit_ids + i_ids + i_ids1
        #                    print "new_ids...........",new_ids
        #                    select_ids = select_obj.search(cr ,uid ,[])
        #                    print "select_ids........",select_ids
        #                    for select_id in select_ids:
        #                        select_obj.unlink(cr ,uid , select_id)
        #                    for new_id in new_ids:
        #                        select_ids = select_obj.create(cr ,uid ,{'interp_id':new_id,'interpreter_id':new_id,})
        #                    new_ids = tuple(new_ids)
        #                    print "new_ids.....",new_ids
        #                    print "list(new_ids).....",list(new_ids)
        #                    print "select_ids.......",select_ids
        #                    new_ids = flatten(new_ids)
        #                    print "new_ids.........",new_ids
        #                    new_ids = list(set(new_ids))
        #                    print "new_ids.........",new_ids
        #            #print "interpreter_ids.......",interpreter_ids
        #        if view_type=='form':
        #            _moves_arch_lst = """<form string="Assign Interpreter" version="7.0">
        #                   """
        #            #<field name="interpreter_id" domain="[('id','in',%s)]" required="1"/> %(list(new_ids))
        #            _moves_arch_lst += """
        #                    <group>
        #
        #                        <field name="interpreter_id2"  />
        #                        <separator/>
        #                        <separator/>
        #                        <field name="interpreter_ids" nolabel="1" >
        #                            <tree editable="top">
        #                                <field name="select" />
        #                                <field name="name" />
        #                                <field name="middle_name" />
        #                                <field name="last_name" />
        #                                <field name="zip" />
        #                                <field name="rate" />
        #                            </tree>
        #                        <field />
        #                    </group>
        #                    <footer>
        #                        <button string="Assign Interpreter" name="update_interpreter" type="object" class="oe_highlight"/>
        #                        or
        #                        <button string="Cancel" class="oe_link" special="cancel" />
        #                    </footer> """
        #            _moves_arch_lst += """ </form>"""
        #            result['arch'] = _moves_arch_lst
        return result

    _columns = {
        #'language_id': fields.many2one("language" ,"Language",ondelete="CASCADE"),
        'event_id':
        fields.many2one(
            "event",
            "Event Id",
        ),
        #'voicemail_msg': fields.char("Voicemail Message" , size=32),
        #'interpreter_id': fields.many2one("hr.employee",'Interpreter', ondelete="CASCADE" ),
        #'interpreter_id2': fields.many2one("select.interpreter",'Interpreter2', ondelete="CASCADE" ),
        #'interpreter_lines': fields.one2many('select.interpreter','assign_id','Interpreters'),
        'interpreter_ids':
        fields.many2many("select.interpreter", 'select_assign_rel', 'wiz_id',
                         'interp_id', "Interpreters"),
    }
Esempio n. 11
0
class ProjectProject(models.Model):
    _inherit = 'project.project'
    task_categ_id = fields.many2one('project.category',
                                    'Root Category for Tasks')