Ejemplo n.º 1
0
class stock_reportcustomer_model(osv.osv):
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    _name = 'stock.reportcustomer.model'
    _description = 'Formulario de las Factuas del Cliente'
    _columns = {
        'name':
        fields.many2one('res.partner', 'Cliente'),
        'date':
        fields.date('Fecha Inicio', required=False),
        'date_end':
        fields.date('Fecha Fin', required=False),
        'reportcustomer_lines':
        fields.one2many('stock.reportcustomer.model.line', 'reportcustomer_id',
                        ' Detalle de los Productos'),
        'reportcustomer_invoice_lines':
        fields.one2many('stock.reportcustomer.invoices.line',
                        'reportcustomer_id', ' Detalle de los Productos'),
        'total_invoices':
        fields.float(
            'Monto Total Facturacion',
            digits=(14, 2),
        )
    }
    _defaults = {}
    _order = 'id desc'
Ejemplo n.º 2
0
Archivo: models.py Proyecto: ecoreos/hz
class One2ManyMultiple(orm.Model):
    _name = 'export.one2many.multiple'
    _columns = {
        'parent_id': fields.many2one('export.one2many.recursive'),
        'const': fields.integer(),
        'child1': fields.one2many('export.one2many.child.1', 'parent_id'),
        'child2': fields.one2many('export.one2many.child.2', 'parent_id'),
    }
    _defaults = {
        'const': 36,
    }
Ejemplo n.º 3
0
class module_category(osv.osv):
    _name = "ir.module.category"
    _description = "Application"

    def _module_nbr(self, cr, uid, ids, prop, unknow_none, context):
        cr.execute(
            'SELECT category_id, COUNT(*) \
                      FROM ir_module_module \
                     WHERE category_id IN %(ids)s \
                        OR category_id IN (SELECT id \
                                             FROM ir_module_category \
                                            WHERE parent_id IN %(ids)s) \
                     GROUP BY category_id', {'ids': tuple(ids)})
        result = dict(cr.fetchall())
        for id in ids:
            cr.execute('select id from ir_module_category where parent_id=%s',
                       (id, ))
            result[id] = sum([result.get(c, 0) for (c, ) in cr.fetchall()],
                             result.get(id, 0))
        return result

    _columns = {
        'name':
        fields.char("Name", required=True, translate=True, select=True),
        'parent_id':
        fields.many2one('ir.module.category',
                        'Parent Application',
                        select=True),
        'child_ids':
        fields.one2many('ir.module.category', 'parent_id',
                        'Child Applications'),
        'module_nr':
        fields.function(_module_nbr, string='Number of Apps', type='integer'),
        'module_ids':
        fields.one2many('ir.module.module', 'category_id', 'Modules'),
        'description':
        fields.text("Description", translate=True),
        'sequence':
        fields.integer('Sequence'),
        'visible':
        fields.boolean('Visible'),
        'xml_id':
        fields.function(osv.osv.get_external_id,
                        type='char',
                        string="External ID"),
    }
    _order = 'name'

    _defaults = {
        'visible': 1,
    }
Ejemplo n.º 4
0
class pos_config(osv.osv):
    _inherit = 'pos.config'
    _columns = {
        'iface_splitbill':
        fields.boolean('Bill Splitting',
                       help='Enables Bill Splitting in the Point of Sale'),
        'iface_printbill':
        fields.boolean('Bill Printing',
                       help='Allows to print the Bill before payment'),
        'iface_orderline_notes':
        fields.boolean('Orderline Notes',
                       help='Allow custom notes on Orderlines'),
        'floor_ids':
        fields.one2many(
            'restaurant.floor',
            'pos_config_id',
            'Restaurant Floors',
            help='The restaurant floors served by this point of sale'),
        'printer_ids':
        fields.many2many('restaurant.printer',
                         'pos_config_printer_rel',
                         'config_id',
                         'printer_id',
                         string='Order Printers'),
    }
    _defaults = {
        'iface_splitbill': False,
        'iface_printbill': False,
    }
Ejemplo n.º 5
0
class res_partner(osv.osv):
    _name = 'res.partner'
    _inherit = 'res.partner'

    def _compute_payment_method_count(self,
                                      cr,
                                      uid,
                                      ids,
                                      field_names,
                                      arg,
                                      context=None):
        result = {}
        payment_data = self.pool['payment.method'].read_group(
            cr,
            uid, [('partner_id', 'in', ids)], ['partner_id'], ['partner_id'],
            context=context)
        mapped_data = dict([(payment['partner_id'][0],
                             payment['partner_id_count'])
                            for payment in payment_data])
        for partner in self.browse(cr, uid, ids, context=context):
            result[partner.id] = mapped_data.get(partner.id, 0)
        return result

    _columns = {
        'payment_method_ids':
        fields.one2many('payment.method', 'partner_id', 'Payment Methods'),
        'payment_method_count':
        fields.function(_compute_payment_method_count,
                        string='Count Payment Method',
                        type="integer"),
    }
Ejemplo n.º 6
0
class product_putaway_strategy(osv.osv):
    _name = 'product.putaway'
    _description = 'Put Away Strategy'

    def _get_putaway_options(self, cr, uid, context=None):
        return [('fixed', 'Fixed Location')]

    _columns = {
        'name':
        fields.char('Name', required=True),
        'method':
        fields.selection(_get_putaway_options, "Method", required=True),
        'fixed_location_ids':
        fields.one2many(
            'stock.fixed.putaway.strat',
            'putaway_id',
            'Fixed Locations Per Product Category',
            help=
            "When the method is fixed, this location will be used to store the products",
            copy=True),
    }

    _defaults = {
        'method': 'fixed',
    }

    def putaway_apply(self, cr, uid, putaway_strat, product, context=None):
        if putaway_strat.method == 'fixed':
            for strat in putaway_strat.fixed_location_ids:
                categ = product.categ_id
                while categ:
                    if strat.category_id.id == categ.id:
                        return strat.fixed_location_id.id
                    categ = categ.parent_id
Ejemplo n.º 7
0
class account_budget_post(osv.osv):
    _name = "account.budget.post"
    _description = "Budgetary Position"
    _columns = {
        'name':
        fields.char('Name', required=True),
        'account_ids':
        fields.many2many('account.account',
                         'account_budget_rel',
                         'budget_id',
                         'account_id',
                         'Accounts',
                         domain=[('deprecated', '=', False)]),
        'crossovered_budget_line':
        fields.one2many('crossovered.budget.lines', 'general_budget_id',
                        'Budget Lines'),
        'company_id':
        fields.many2one('res.company', 'Company', required=True),
    }
    _defaults = {
        'company_id':
        lambda self, cr, uid, c: self.pool.get('res.company').
        _company_default_get(cr, uid, 'account.budget.post', context=c)
    }
    _order = "name"
Ejemplo n.º 8
0
class PaymentMethod(osv.Model):
    _name = 'payment.method'
    _order = 'partner_id'

    _columns = {
        'name': fields.char('Name', help='Name of the payment method'),
        'partner_id': fields.many2one('res.partner', 'Partner', required=True),
        'acquirer_id': fields.many2one('payment.acquirer', 'Acquirer Account', required=True),
        'acquirer_ref': fields.char('Acquirer Ref.', required=True),
        'active': fields.boolean('Active'),
        'payment_ids': fields.one2many('payment.transaction', 'payment_method_id', 'Payment Transactions'),
    }

    _defaults = {
        'active': True
    }

    def create(self, cr, uid, values, context=None):
        # call custom create method if defined (i.e. ogone_create for ogone)
        if values.get('acquirer_id'):
            acquirer = self.pool['payment.acquirer'].browse(cr, uid, values.get('acquirer_id'), context=context)

            # custom create
            custom_method_name = '%s_create' % acquirer.provider
            if hasattr(self, custom_method_name):
                values.update(getattr(self, custom_method_name)(cr, uid, values, context=context))

        return super(PaymentMethod, self).create(cr, uid, values, context=context)
Ejemplo n.º 9
0
class res_state(osv.osv):

    def name_get(self, cr, uid, ids, context=None):
        if not len(ids):
            return []
        res = []
        for state in self.browse(cr, uid, ids, context=context):
            data = []
            acc = state
            while acc:
                data.insert(0, acc.name)
                acc = acc.parent_id
            data = ' / '.join(data)
            res.append((state.id, (state.code and '[' + state.code + '] ' or '') + data))
        
        return res
        
    
    def complete_name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
        if not args:
            args = []
        args = args[:]
        ids = []
        if name:
            ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit)
            if not ids and len(name.split()) >= 2:
                #Separating code and name of account for searching
                operand1,operand2 = name.split(': ',1) #name can contain spaces e.g. eCore
                ids = self.search(cr, user, [('name', operator, operand2)]+ args, limit=limit)
        else:
            ids = self.search(cr, user, args, context=context, limit=limit)
        return self.name_get(cr, user, ids, context=context)
    
    def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
        if not ids:
            return []
        res = []
        for state in self.browse(cr, uid, ids, context=context):
            data = []
            acc = state
            while acc:
                data.insert(0, acc.name)
                acc = acc.parent_id
            data = ' / '.join(data)
            res.append((state.id, data))
        return dict(res)
        
    _name = 'res.country.state'
    _inherit = 'res.country.state'
    _columns = {
            'code': fields.char('State Code', size=32,help='The state code.\n', required=True),
            'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Complete Name', fnct_search=complete_name_search),
            'parent_id': fields.many2one('res.country.state','Parent State', select=True, domain=[('type','=','view')]),
            'child_ids': fields.one2many('res.country.state', 'parent_id', string='Child States'),
            'type': fields.selection([('view','View'), ('normal','Normal')], 'Type'),
        }
    _defaults = {
            'type': 'normal',
        }
Ejemplo n.º 10
0
class account_analytic_account(osv.osv):
    _inherit = "account.analytic.account"

    _columns = {
        'crossovered_budget_line':
        fields.one2many('crossovered.budget.lines', 'analytic_account_id',
                        'Budget Lines'),
    }
Ejemplo n.º 11
0
class project_issue(osv.osv):
    _inherit = 'project.issue'
    _description = 'project issue'

    def _hours_get(self, cr, uid, ids, field_names, args, context=None):
        res = {}
        for issue in self.browse(cr, uid, ids, context=context):
            res[issue.id] = {'progress': issue.task_id.progress or 0.0}
        return res

    def _get_issue_task(self, cr, uid, task_ids, context=None):
        return self.pool['project.issue'].search(cr,
                                                 uid,
                                                 [('task_id', 'in', task_ids)],
                                                 context=context)

    _columns = {
        'progress':
        fields.function(_hours_get,
                        string='Progress (%)',
                        multi='line_id',
                        group_operator="avg",
                        help="Computed as: Time Spent / Total Time.",
                        store={
                            'project.issue':
                            (lambda self, cr, uid, ids, c={}: ids, ['task_id'],
                             10),
                            'project.task':
                            (_get_issue_task, ['progress'], 10),
                        }),
        'timesheet_ids':
        fields.one2many('account.analytic.line', 'issue_id', 'Timesheets'),
        'analytic_account_id':
        fields.many2one('account.analytic.account', 'Analytic Account'),
    }

    def on_change_project(self, cr, uid, ids, project_id, context=None):
        if not project_id:
            return {'value': {'analytic_account_id': False}}

        result = super(project_issue, self).on_change_project(cr,
                                                              uid,
                                                              ids,
                                                              project_id,
                                                              context=context)

        project = self.pool.get('project.project').browse(cr,
                                                          uid,
                                                          project_id,
                                                          context=context)
        if 'value' not in result:
            result['value'] = {}

        account = project.analytic_account_id
        if account:
            result['value']['analytic_account_id'] = account.id

        return result
Ejemplo n.º 12
0
class mrp_bom(osv.osv):
    _name = 'mrp.bom'
    _description = 'Bill of Material'
    _inherit = 'mrp.bom'

    _columns = {
        'sub_products':
        fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts', copy=True),
    }
Ejemplo n.º 13
0
class lead_test(osv.Model):
    _name = "base.action.rule.lead.test"
    _description = "Action Rule Test"

    _columns = {
        'name':
        fields.char('Subject', required=True, select=1),
        'user_id':
        fields.many2one('res.users', 'Responsible'),
        'state':
        fields.selection(AVAILABLE_STATES, string="Status", readonly=True),
        'active':
        fields.boolean('Active', required=False),
        'partner_id':
        fields.many2one('res.partner', 'Partner', ondelete='set null'),
        'date_action_last':
        fields.datetime('Last Action', readonly=1),
        'line_ids':
        fields.one2many('base.action.rule.line.test', 'lead_id'),
    }

    _defaults = {
        'state': 'draft',
        'active': True,
    }

    customer = ecore.fields.Boolean(related='partner_id.customer',
                                    readonly=True,
                                    store=True)

    @api.cr_uid_ids_context
    def message_post(self,
                     cr,
                     uid,
                     thread_id,
                     body='',
                     subject=None,
                     message_type='notification',
                     subtype=None,
                     parent_id=False,
                     attachments=None,
                     context=None,
                     **kwargs):
        pass

    def message_subscribe(self,
                          cr,
                          uid,
                          ids,
                          partner_ids=None,
                          channel_ids=None,
                          subtype_ids=None,
                          force=True,
                          context=None):
        pass
Ejemplo n.º 14
0
class sale_quote_template(osv.osv):
    _name = "sale.quote.template"
    _description = "Sale Quotation Template"
    _columns = {
        'name':
        fields.char('Quotation Template', required=True),
        'website_description':
        fields.html('Description', translate=True),
        'quote_line':
        fields.one2many('sale.quote.line',
                        'quote_id',
                        'Quotation Template Lines',
                        copy=True),
        'note':
        fields.text('Terms and conditions'),
        'options':
        fields.one2many('sale.quote.option',
                        'template_id',
                        'Optional Products Lines',
                        copy=True),
        'number_of_days':
        fields.integer(
            'Quotation Duration',
            help=
            'Number of days for the validity date computation of the quotation'
        ),
        'require_payment':
        fields.selection(
            [(0, 'Not mandatory on website quote validation'),
             (1, 'Immediate after website order validation')],
            'Payment',
            help=
            "Require immediate payment by the customer when validating the order from the website quote"
        ),
    }

    def open_template(self, cr, uid, quote_id, context=None):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/quote/template/%d' % quote_id[0]
        }
Ejemplo n.º 15
0
class res_users(osv.Model):
    """ Update of res.users class

     - add field for the related employee of the user
     - if adding groups to an user, check if base.group_user is in it (member of
       'Employee'), create an employee form linked to it. """
    _name = 'res.users'
    _inherit = ['res.users']

    _columns = {
        'employee_ids':
        fields.one2many('hr.employee', 'user_id', 'Related employees'),
    }

    def _message_post_get_eid(self, cr, uid, thread_id, context=None):
        assert thread_id, "res.users does not support posting global messages"
        if context and 'thread_model' in context:
            context = dict(context or {})
            context['thread_model'] = 'hr.employee'
        if isinstance(thread_id, (list, tuple)):
            thread_id = thread_id[0]
        return self.pool.get('hr.employee').search(
            cr, uid, [('user_id', '=', thread_id)], context=context)

    @api.cr_uid_ids_context
    def message_post(self, cr, uid, thread_id, context=None, **kwargs):
        """ Redirect the posting of message on res.users to the related employee.
            This is done because when giving the context of Chatter on the
            various mailboxes, we do not have access to the current partner_id. """
        if kwargs.get('message_type') == 'email':
            return super(res_users, self).message_post(cr,
                                                       uid,
                                                       thread_id,
                                                       context=context,
                                                       **kwargs)
        res = None
        employee_ids = self._message_post_get_eid(cr,
                                                  uid,
                                                  thread_id,
                                                  context=context)
        if not employee_ids:  # no employee: fall back on previous behavior
            return super(res_users, self).message_post(cr,
                                                       uid,
                                                       thread_id,
                                                       context=context,
                                                       **kwargs)
        for employee_id in employee_ids:
            res = self.pool.get('hr.employee').message_post(cr,
                                                            uid,
                                                            employee_id,
                                                            context=context,
                                                            **kwargs)
        return res
Ejemplo n.º 16
0
class ir_exports(osv.osv):
    _name = "ir.exports"
    _order = 'name'
    _columns = {
        'name':
        fields.char('Export Name'),
        'resource':
        fields.char('Resource', select=True),
        'export_fields':
        fields.one2many('ir.exports.line', 'export_id', 'Export ID',
                        copy=True),
    }
Ejemplo n.º 17
0
class product(osv.osv):
    _inherit = 'product.product'
    _columns = {
        'event_ticket_ids':
        fields.one2many('event.event.ticket', 'product_id', 'Event Tickets'),
    }

    def onchange_event_ok(self, cr, uid, ids, type, event_ok, context=None):
        """ Redirection, inheritance mechanism hides the method on the model """
        if event_ok:
            return {'value': {'type': 'service'}}
        return {}
Ejemplo n.º 18
0
class Country(osv.osv):
    _name = 'res.country'
    _description = 'Country'
    _columns = {
        'name': fields.char('Country Name',
                            help='The full name of the country.', required=True, translate=True),
        'code': fields.char('Country Code', size=2,
                            help='The ISO country code in two chars.\n'
                            'You can use this field for quick search.'),
        'address_format': fields.text('Address Format', help="""You can state here the usual format to use for the \
addresses belonging to this country.\n\nYou can use the python-style string patern with all the field of the address \
(for example, use '%(street)s' to display the field 'street') plus
            \n%(state_name)s: the name of the state
            \n%(state_code)s: the code of the state
            \n%(country_name)s: the name of the country
            \n%(country_code)s: the code of the country"""),
        'currency_id': fields.many2one('res.currency', 'Currency'),
        'image': fields.binary("Image", attachment=True),
        'phone_code': fields.integer('Country Calling Code'),
        'country_group_ids': fields.many2many('res.country.group', 'res_country_res_country_group_rel', 'res_country_id', 'res_country_group_id', string='Country Groups'),
        'state_ids': fields.one2many('res.country.state', 'country_id', string='States'),
    }
    _sql_constraints = [
        ('name_uniq', 'unique (name)',
            'The name of the country must be unique !'),
        ('code_uniq', 'unique (code)',
            'The code of the country must be unique !')
    ]
    _defaults = {
        'address_format': "%(street)s\n%(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s",
    }
    _order = 'name'

    name_search = location_name_search

    def create(self, cursor, user, vals, context=None):
        if vals.get('code'):
            vals['code'] = vals['code'].upper()
        return super(Country, self).create(cursor, user, vals, context=context)

    def write(self, cursor, user, ids, vals, context=None):
        if vals.get('code'):
            vals['code'] = vals['code'].upper()
        return super(Country, self).write(cursor, user, ids, vals, context=context)

    def get_address_fields(self, cr, uid, ids, context=None):
        res = {}
        for country in self.browse(cr, uid, ids, context=context):
            res[country.id] = re.findall('\((.+?)\)', country.address_format)
        return res
Ejemplo n.º 19
0
class workflow(osv.osv):
    _name = "workflow"
    _table = "wkf"
    _order = "name"
    _columns = {
        'name': fields.char('Name', required=True),
        'osv': fields.char('Resource Object', required=True, select=True),
        'on_create': fields.boolean('On Create', select=True),
        'activities': fields.one2many('workflow.activity', 'wkf_id',
                                      'Activities'),
    }
    _defaults = {'on_create': lambda *a: True}

    def copy(self, cr, uid, id, values, context=None):
        raise UserError(
            _("Duplicating workflows is not possible, please create a new workflow"
              ))

    def write(self, cr, user, ids, vals, context=None):
        if not context:
            context = {}
        ecore.workflow.clear_cache(cr, user)
        return super(workflow, self).write(cr,
                                           user,
                                           ids,
                                           vals,
                                           context=context)

    def get_active_workitems(self, cr, uid, res, res_id, context=None):
        cr.execute('select * from wkf where osv=%s limit 1', (res, ))
        wkfinfo = cr.dictfetchone()
        workitems = []
        if wkfinfo:
            cr.execute(
                'SELECT id FROM wkf_instance \
                            WHERE res_id=%s AND wkf_id=%s \
                            ORDER BY state LIMIT 1', (res_id, wkfinfo['id']))
            inst_id = cr.fetchone()

            cr.execute(
                'select act_id,count(*) from wkf_workitem where inst_id=%s group by act_id',
                (inst_id, ))
            workitems = dict(cr.fetchall())
        return {'wkf': wkfinfo, 'workitems': workitems}

    def create(self, cr, user, vals, context=None):
        if not context:
            context = {}
        ecore.workflow.clear_cache(cr, user)
        return super(workflow, self).create(cr, user, vals, context=context)
Ejemplo n.º 20
0
class wizard(osv.osv_memory):
    """
        A wizard to manage the creation/removal of portal users.
    """
    _name = 'portal.wizard'
    _description = 'Portal Access Management'

    _columns = {
        'portal_id': fields.many2one('res.groups', domain=[('is_portal', '=', True)], required=True,
            string='Portal', help="The portal that users can be added in or removed from."),
        'user_ids': fields.one2many('portal.wizard.user', 'wizard_id', string='Users'),
        'welcome_message': fields.text(string='Invitation Message',
            help="This text is included in the email sent to new users of the portal."),
    }

    def _default_portal(self, cr, uid, context):
        portal_ids = self.pool.get('res.groups').search(cr, uid, [('is_portal', '=', True)])
        return portal_ids and portal_ids[0] or False

    _defaults = {
        'portal_id': _default_portal,
    }

    def onchange_portal_id(self, cr, uid, ids, portal_id, context=None):
        # for each partner, determine corresponding portal.wizard.user records
        res_partner = self.pool.get('res.partner')
        partner_ids = context and context.get('active_ids') or []
        contact_ids = set()
        user_changes = []
        for partner in res_partner.browse(cr, SUPERUSER_ID, partner_ids, context):
            for contact in (partner.child_ids or [partner]):
                # make sure that each contact appears at most once in the list
                if contact.id not in contact_ids:
                    contact_ids.add(contact.id)
                    in_portal = False
                    if contact.user_ids:
                        in_portal = portal_id in [g.id for g in contact.user_ids[0].groups_id]
                    user_changes.append((0, 0, {
                        'partner_id': contact.id,
                        'email': contact.email,
                        'in_portal': in_portal,
                    }))
        return {'value': {'user_ids': user_changes}}

    def action_apply(self, cr, uid, ids, context=None):
        wizard = self.browse(cr, uid, ids[0], context)
        portal_user_ids = [user.id for user in wizard.user_ids]
        self.pool.get('portal.wizard.user').action_apply(cr, uid, portal_user_ids, context)
        return {'type': 'ir.actions.act_window_close'}
Ejemplo n.º 21
0
class MailThread(osv.AbstractModel):
    _inherit = 'mail.thread'

    _columns = {
        'website_message_ids':
        fields.one2many(
            'mail.message',
            'res_id',
            domain=lambda self: [
                '&', ('model', '=', self._name),
                ('message_type', '=', 'comment')
            ],
            string='Website Messages',
            help="Website communication history",
        ),
    }
Ejemplo n.º 22
0
class crm_team(osv.Model):
    _name = "crm.team"
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    _description = "Sales Team"
    _order = "name"
    _period_number = 5

    def _get_default_team_id(self, cr, uid, context=None, user_id=None):
        if context is None:
            context = {}
        if user_id is None:
            user_id = uid
        team_id = context.get('default_team_id')
        if not team_id:
            team_ids = self.search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', 'in', user_id)], limit=1, context=context)
            team_id = team_ids[0] if team_ids else False
        if not team_id:
            team_id = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'sales_team.team_sales_department')
        return team_id

    _columns = {
        'name': fields.char('Sales Team', size=64, required=True, translate=True),
        'code': fields.char('Code', size=8),
        'active': fields.boolean('Active', help="If the active field is set to "\
                        "false, it will allow you to hide the sales team without removing it."),
        'company_id': fields.many2one('res.company', 'Company'),
        'user_id': fields.many2one('res.users', 'Team Leader'),
        'member_ids': fields.one2many('res.users', 'sale_team_id', 'Team Members'),
        'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by eCore about cases in this sales team"),
        'working_hours': fields.float('Working Hours', digits=(16, 2)),
        'color': fields.integer('Color Index'),
    }

    _defaults = {
        'active': 1,
        'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'crm.team', context=context),
    }

    _sql_constraints = [
        ('code_uniq', 'unique (code)', 'The code of the sales team must be unique !')
    ]

    def create(self, cr, uid, values, context=None):
        if context is None:
            context = {}
        context['mail_create_nosubscribe'] = True
        return super(crm_team, self).create(cr, uid, values, context=context)
Ejemplo n.º 23
0
class sale_order_line(osv.osv):
    _inherit = "sale.order.line"
    _description = "Sales Order Line"
    _columns = {
        'website_description':
        fields.html('Line Description'),
        'option_line_id':
        fields.one2many('sale.order.option', 'line_id',
                        'Optional Products Lines'),
    }

    def _inject_quote_description(self, cr, uid, values, context=None):
        values = dict(values or {})
        if not values.get('website_description') and values.get('product_id'):
            product = self.pool['product.product'].browse(cr,
                                                          uid,
                                                          values['product_id'],
                                                          context=context)
            values[
                'website_description'] = product.quote_description or product.website_description
        return values

    def create(self, cr, uid, values, context=None):
        values = self._inject_quote_description(cr, uid, values, context)
        ret = super(sale_order_line, self).create(cr,
                                                  uid,
                                                  values,
                                                  context=context)
        # hack because create don t make the job for a related field
        if values.get('website_description'):
            self.write(cr,
                       uid,
                       ret,
                       {'website_description': values['website_description']},
                       context=context)
        return ret

    def write(self, cr, uid, ids, values, context=None):
        values = self._inject_quote_description(cr, uid, values, context)
        return super(sale_order_line, self).write(cr,
                                                  uid,
                                                  ids,
                                                  values,
                                                  context=context)
Ejemplo n.º 24
0
class procurement_group(osv.osv):
    '''
    The procurement group class is used to group products together
    when computing procurements. (tasks, physical products, ...)

    The goal is that when you have one sale order of several products
    and the products are pulled from the same or several location(s), to keep
    having the moves grouped into pickings that represent the sale order.

    Used in: sales order (to group delivery order lines like the so), pull/push
    rules (to pack like the delivery order), on orderpoints (e.g. for wave picking
    all the similar products together).

    Grouping is made only if the source and the destination is the same.
    Suppose you have 4 lines on a picking from Output where 2 lines will need
    to come from Input (crossdock) and 2 lines coming from Stock -> Output As
    the four procurement orders will have the same group ids from the SO, the
    move from input will have a stock.picking with 2 grouped lines and the move
    from stock will have 2 grouped lines also.

    The name is usually the name of the original document (sale order) or a
    sequence computed if created manually.
    '''
    _name = 'procurement.group'
    _description = 'Procurement Requisition'
    _order = "id desc"
    _columns = {
        'name':
        fields.char('Reference', required=True),
        'move_type':
        fields.selection([('direct', 'Partial'), ('one', 'All at once')],
                         'Delivery Method',
                         required=True),
        'procurement_ids':
        fields.one2many('procurement.order', 'group_id', 'Procurements'),
    }
    _defaults = {
        'name':
        lambda self, cr, uid, c: self.pool.get('ir.sequence').next_by_code(
            cr, uid, 'procurement.group') or '',
        'move_type':
        lambda self, cr, uid, c: 'direct'
    }
Ejemplo n.º 25
0
class res_partner(osv.osv):
    def _task_count(self, cr, uid, ids, field_name, arg, context=None):
        Task = self.pool['project.task']
        return {
            partner_id: Task.search_count(cr,
                                          uid,
                                          [('partner_id', '=', partner_id)],
                                          context=context)
            for partner_id in ids
        }

    """ Inherits partner and adds Tasks information in the partner form """
    _inherit = 'res.partner'
    _columns = {
        'task_ids':
        fields.one2many('project.task', 'partner_id', 'Tasks'),
        'task_count':
        fields.function(_task_count, string='# Tasks', type='integer'),
    }
Ejemplo n.º 26
0
class project(osv.Model):
    _inherit = "project.project"

    def _get_alias_models(self, cr, uid, context=None):
        res = super(project, self)._get_alias_models(cr, uid, context=context)
        res.append(("project.issue", "Issues"))
        return res

    def _issue_count(self, cr, uid, ids, field_name, arg, context=None):
        Issue = self.pool['project.issue']
        return {
            project_id: Issue.search_count(cr,
                                           uid,
                                           [('project_id', '=', project_id),
                                            ('stage_id.fold', '=', False)],
                                           context=context)
            for project_id in ids
        }

    _columns = {
        'issue_count':
        fields.function(
            _issue_count,
            type='integer',
            string="Issues",
        ),
        'issue_ids':
        fields.one2many('project.issue',
                        'project_id',
                        string="Issues",
                        domain=[('stage_id.fold', '=', False)]),
    }

    @api.multi
    def write(self, vals):
        res = super(project, self).write(vals)
        if 'active' in vals:
            # archiving/unarchiving a project does it on its issues, too
            issues = self.with_context(active_test=False).mapped('issue_ids')
            issues.write({'active': vals['active']})
        return res
Ejemplo n.º 27
0
class res_partner(osv.osv):
    _inherit = "res.partner"
    _columns = {
        'partner_weight':
        fields.integer(
            'Level Weight',
            help=
            "Gives the probability to assign a lead to this partner. (0 means no assignation.)"
        ),
        'grade_id':
        fields.many2one('res.partner.grade', 'Level'),
        'activation':
        fields.many2one('res.partner.activation', 'Activation', select=1),
        'date_partnership':
        fields.date('Partnership Date'),
        'date_review':
        fields.date('Latest Partner Review'),
        'date_review_next':
        fields.date('Next Partner Review'),
        # customer implementation
        'assigned_partner_id':
        fields.many2one(
            'res.partner',
            'Implemented by',
        ),
        'implemented_partner_ids':
        fields.one2many(
            'res.partner',
            'assigned_partner_id',
            string='Implementation References',
        ),
    }
    _defaults = {'partner_weight': lambda *args: 0}

    def onchange_grade_id(self, cr, uid, ids, grade_id, context=None):
        res = {'value': {'partner_weight': 0}}
        if grade_id:
            partner_grade = self.pool.get('res.partner.grade').browse(
                cr, uid, grade_id)
            res['value']['partner_weight'] = partner_grade.partner_weight
        return res
Ejemplo n.º 28
0
class restaurant_floor(osv.osv):
    _name = 'restaurant.floor'
    _columns = {
        'name':
        fields.char('Floor Name',
                    required=True,
                    help='An internal identification of the restaurant floor'),
        'pos_config_id':
        fields.many2one('pos.config', 'Point of Sale'),
        'background_image':
        fields.binary(
            'Background Image',
            attachment=True,
            help=
            'A background image used to display a floor layout in the point of sale interface'
        ),
        'background_color':
        fields.char(
            'Background Color',
            help=
            'The background color of the floor layout, (must be specified in a html-compatible format)'
        ),
        'table_ids':
        fields.one2many('restaurant.table',
                        'floor_id',
                        'Tables',
                        help='The list of tables in this floor'),
        'sequence':
        fields.integer('Sequence', help='Used to sort Floors'),
    }

    _defaults = {
        'sequence': 1,
        'background_color': 'rgb(210, 210, 210)',
    }

    def set_background_color(self, cr, uid, id, background, context=None):
        self.write(cr,
                   uid, [id], {'background_color': background},
                   context=context)
Ejemplo n.º 29
0
class change_password_wizard(osv.TransientModel):
    """
        A wizard to manage the change of users' passwords
    """

    _name = "change.password.wizard"
    _description = "Change Password Wizard"
    _columns = {
        'user_ids': fields.one2many('change.password.user', 'wizard_id', string='Users'),
    }

    def _default_user_ids(self, cr, uid, context=None):
        if context is None:
            context = {}
        user_model = self.pool['res.users']
        user_ids = context.get('active_model') == 'res.users' and context.get('active_ids') or []
        return [
            (0, 0, {'user_id': user.id, 'user_login': user.login})
            for user in user_model.browse(cr, uid, user_ids, context=context)
        ]

    _defaults = {
        'user_ids': _default_user_ids,
    }

    def change_password_button(self, cr, uid, ids, context=None):
        wizard = self.browse(cr, uid, ids, context=context)[0]
        need_reload = any(uid == user.user_id.id for user in wizard.user_ids)

        line_ids = [user.id for user in wizard.user_ids]
        self.pool.get('change.password.user').change_password_button(cr, uid, line_ids, context=context)

        if need_reload:
            return {
                'type': 'ir.actions.client',
                'tag': 'reload'
            }

        return {'type': 'ir.actions.act_window_close'}
Ejemplo n.º 30
0
class res_partner(osv.osv):
    _inherit = 'res.partner'

    def _sale_order_count(self, cr, uid, ids, field_name, arg, context=None):
        res = dict(map(lambda x: (x, 0), ids))
        # The current user may not have access rights for sale orders
        try:
            for partner in self.browse(cr, uid, ids, context):
                res[partner.id] = len(partner.sale_order_ids) + len(
                    partner.mapped('child_ids.sale_order_ids'))
        except:
            pass
        return res

    _columns = {
        'sale_order_count':
        fields.function(_sale_order_count,
                        string='# of Sales Order',
                        type='integer'),
        'sale_order_ids':
        fields.one2many('sale.order', 'partner_id', 'Sales Order')
    }
Ejemplo n.º 31
0
    ('boolean', fields.boolean()),
    ('integer', fields.integer()),
    ('float', fields.float()),
    ('decimal', fields.float(digits=(16, 3))),
    ('string.bounded', fields.char('unknown', size=16)),
    ('string.required', fields.char('unknown', size=None, required=True)),
    ('string', fields.char('unknown', size=None)),
    ('date', fields.date()),
    ('datetime', fields.datetime()),
    ('text', fields.text()),
    ('selection', fields.selection([(1, "Foo"), (2, "Bar"), (3, "Qux"), (4, '')])),
    # here use size=-1 to store the values as integers instead of strings
    ('selection.function', fields.selection(selection_fn, size=-1)),
    # just relate to an integer
    ('many2one', fields.many2one('export.integer')),
    ('one2many', fields.one2many('export.one2many.child', 'parent_id')),
    ('many2many', fields.many2many('export.many2many.other')),
    ('function', fields.function(function_fn, fnct_inv=function_fn_write, type="integer")),
    # related: specialization of fields.function, should work the same way
    # TODO: reference
]

for name, field in models:
    class NewModel(orm.Model):
        _name = 'export.%s' % name
        _columns = {
            'const': fields.integer(),
            'value': field,
        }
        _defaults = {
            'const': 4,