Beispiel #1
0
 def create(self, vals):
     if vals.get('user_id'):
         vals.update(
             self._sync_user(self.env['res.users'].browse(vals['user_id'])))
     tools.image_resize_images(vals)
     employee = super(Employee, self).create(vals)
     if employee.department_id:
         self.env['mail.channel'].sudo().search([
             ('subscription_department_ids', 'in',
              employee.department_id.id)
         ])._subscribe_users()
     return employee
Beispiel #2
0
    def write(self, vals):
        if vals.get('active') is False:
            for partner in self:
                if partner.active and partner.user_ids:
                    raise ValidationError(
                        _('You cannot archive a contact linked to an internal user.'
                          ))
        # res.partner must only allow to set the company_id of a partner if it
        # is the same as the company of all users that inherit from this partner
        # (this is to allow the code from res_users to write to the partner!) or
        # if setting the company_id to False (this is compatible with any user
        # company)
        if vals.get('website'):
            vals['website'] = self._clean_website(vals['website'])
        if vals.get('parent_id'):
            vals['company_name'] = False
        if vals.get('company_id'):
            company = self.env['res.company'].browse(vals['company_id'])
            for partner in self:
                if partner.user_ids:
                    companies = set(user.company_id
                                    for user in partner.user_ids)
                    if len(companies) > 1 or company not in companies:
                        raise UserError((
                            "The selected company is not compatible with the companies of the related user(s)"
                        ))
        tools.image_resize_images(vals, sizes={'image': (1024, None)})

        result = True
        # To write in SUPERUSER on field is_company and avoid access rights problems.
        if 'is_company' in vals and self.user_has_groups(
                'base.group_partner_manager'
        ) and not self.env.uid == SUPERUSER_ID:
            result = super(Partner, self.sudo()).write(
                {'is_company': vals.get('is_company')})
            del vals['is_company']
        result = result and super(Partner, self).write(vals)
        for partner in self:
            if any(
                    u.has_group('base.group_user') for u in partner.user_ids
                    if u != self.env.user):
                self.env['res.users'].check_access_rights('write')
            partner._fields_sync(vals)
        return result
Beispiel #3
0
 def write(self, vals):
     if 'address_home_id' in vals:
         account_id = vals.get('bank_account_id') or self.bank_account_id.id
         if account_id:
             self.env['res.partner.bank'].browse(
                 account_id).partner_id = vals['address_home_id']
     if vals.get('user_id'):
         vals.update(
             self._sync_user(self.env['res.users'].browse(vals['user_id'])))
     tools.image_resize_images(vals)
     res = super(Employee, self).write(vals)
     if vals.get('department_id') or vals.get('user_id'):
         department_id = vals['department_id'] if vals.get(
             'department_id') else self[:1].department_id.id
         # When added to a department or changing user, subscribe to the channels auto-subscribed by department
         self.env['mail.channel'].sudo().search([
             ('subscription_department_ids', 'in', department_id)
         ])._subscribe_users()
     return res
Beispiel #4
0
    def create(self, vals_list):
        if self.env.context.get('import_file'):
            self._check_import_consistency(vals_list)
        for vals in vals_list:
            if vals.get('website'):
                vals['website'] = self._clean_website(vals['website'])
            if vals.get('parent_id'):
                vals['company_name'] = False
            # compute default image in create, because computing gravatar in the onchange
            # cannot be easily performed if default images are in the way
            if not vals.get('image'):
                vals['image'] = self._get_default_image(
                    vals.get('type'), vals.get('is_company'),
                    vals.get('parent_id'))
            tools.image_resize_images(vals, sizes={'image': (1024, None)})
        partners = super(Partner, self).create(vals_list)

        if self.env.context.get('_partners_skip_fields_sync'):
            return partners

        for partner, vals in pycompat.izip(partners, vals_list):
            partner._fields_sync(vals)
            partner._handle_first_contact_creation()
        return partners
Beispiel #5
0
 def write(self, vals):
     tools.image_resize_images(vals)
     return super(ProductPublicCategory, self).write(vals)
Beispiel #6
0
 def write(self, vals):
     tools.image_resize_images(vals)
     return super(ImLivechatChannel, self).write(vals)
Beispiel #7
0
 def write(self, vals):
     tools.image_resize_images(vals)
     return super(FleetVehicleModelBrand, self).write(vals)
Beispiel #8
0
 def create(self, vals_list):
     for vals in vals_list:
         tools.image_resize_images(vals)
     return super(FleetVehicleModelBrand, self).create(vals_list)
Beispiel #9
0
 def write(self, vals):
     tools.image_resize_images(vals)
     return super(PosCategory, self).write(vals)