Esempio n. 1
0
 def _check_sale_line_type(self):
     for task in self.sudo():
         if task.sale_line_id:
             if not task.sale_line_id.is_service or task.sale_line_id.is_expense:
                 raise ValidationError(
                     _(
                         'You cannot link the order item %(order_id)s - %(product_id)s to this task because it is a re-invoiced expense.',
                         order_id=task.sale_line_id.order_id.name,
                         product_id=task.sale_line_id.product_id.
                         display_name,
                     ))
Esempio n. 2
0
 def _check_answer_type(self):
     for uil in self:
         fields_type = {
             'text': bool(uil.value_text),
             'number': (bool(uil.value_number) or uil.value_number == 0),
             'date': bool(uil.value_date),
             'free_text': bool(uil.value_free_text),
             'suggestion': bool(uil.value_suggested)
         }
         if not fields_type.get(uil.answer_type, True):
             raise ValidationError(_('The answer must be in the right type'))
Esempio n. 3
0
 def _check_holidays(self):
     for holiday in self:
         if holiday.holiday_type != 'employee' or holiday.type != 'remove' or not holiday.employee_id or holiday.holiday_status_id.limit:
             continue
         leave_days = holiday.holiday_status_id.get_days(
             holiday.employee_id.id)[holiday.holiday_status_id.id]
         if float_compare(leave_days['remaining_leaves'], 0, precision_digits=2) == -1 or \
           float_compare(leave_days['virtual_remaining_leaves'], 0, precision_digits=2) == -1:
             raise ValidationError(
                 _('The number of remaining leaves is not sufficient for this leave type.\n'
                   'Please verify also the leaves waiting for validation.'))
Esempio n. 4
0
 def _check_exoneration_with_no_tax(self):
     for tax in self:
         if tax.l10n_it_has_exoneration:
             if not tax.l10n_it_kind_exoneration or not tax.l10n_it_law_reference or tax.amount != 0:
                 raise ValidationError(
                     _("If the tax has exoneration, you must enter a kind of exoneration, a law reference and the amount of the tax must be 0.0."
                       ))
             if tax.l10n_it_kind_exoneration == 'N6' and tax.l10n_it_vat_due_date == 'S':
                 raise UserError(
                     _("'Scissione dei pagamenti' is not compatible with exoneration of kind 'N6'"
                       ))
 def _check_account_ids(self, vals):
     # Raise an error to prevent the account.budget.post to have not specified account_ids.
     # This check is done on create because require=True doesn't work on Many2many fields.
     if 'account_ids' in vals:
         account_ids = self.resolve_2many_commands('account_ids',
                                                   vals['account_ids'])
     else:
         account_ids = self.account_ids
     if not account_ids:
         raise ValidationError(
             _('The budget must have at least one account.'))
Esempio n. 6
0
 def write(self, vals):
     # timesheet product can't be archived
     test_mode = getattr(threading.currentThread(), 'testing',
                         False) or self.env.registry.in_test_mode()
     if not test_mode and 'active' in vals and not vals['active']:
         time_product = self.env.ref('sale_timesheet.time_product')
         if time_product in self:
             raise ValidationError(
                 _('The %s product is required by the Timesheet app and cannot be archived/deleted.'
                   ) % time_product.name)
     return super(ProductProduct, self).write(vals)
Esempio n. 7
0
 def _check_branch(self):
     dropshipping = self.env.ref("stock_dropshipping.picking_type_dropship")
     for order in self:
         warehouse_branch_id = order.picking_type_id.warehouse_id.branch_id
         if order.branch_id and warehouse_branch_id != order.branch_id and order.picking_type_id != dropshipping:
             raise ValidationError(_('Configuration Error of Branch:\n'
                                     'The Purchase Order Branch (%s) and '
                                     'the Warehouse Branch (%s) of Deliver To must '
                                     'be the same branch!') % (
                                   order.branch_id.name,
                                   warehouse_branch_id.name))
Esempio n. 8
0
 def _check_attribute_value_ids(self):
     for product in self:
         attributes = self.env['product.attribute']
         for value in product.attribute_value_ids:
             if value.attribute_id in attributes:
                 raise ValidationError(
                     _('Error! It is not allowed to choose more than one value for a given attribute.'
                       ))
             if value.attribute_id.create_variant:
                 attributes |= value.attribute_id
     return True
Esempio n. 9
0
 def _validate_fiscalyear_lock(self, values):
     if values.get('fiscalyear_lock_date'):
         nb_draft_entries = self.env['account.move'].search([
             ('company_id', 'in', [c.id for c in self]),
             ('state', '=', 'draft'),
             ('date', '<=', values['fiscalyear_lock_date'])
         ])
         if nb_draft_entries:
             raise ValidationError(
                 _('There are still unposted entries in the period you want to lock. You should either post or delete them.'
                   ))
Esempio n. 10
0
 def _check_required_if_provider(self):
     """ If the field has 'required_if_provider="<provider>"' attribute, then it
     required if record.provider is <provider>. """
     empty_field = []
     for acquirer in self:
         for k, f in acquirer._fields.items():
             if getattr(f, 'required_if_provider', None) == acquirer.provider and not acquirer[k]:
                 empty_field.append(self.env['ir.model.fields'].search([('name', '=', k), ('model', '=', acquirer._name)]).field_description)
     if empty_field:
         raise ValidationError((', ').join(empty_field))
     return True
Esempio n. 11
0
 def _check_fiscalyear(self):
     # We try if the date exists in 2020, which is a leap year.
     # We do not define the constrain on res.company, since the recomputation of the related
     # fields is done one field at a time.
     for wiz in self:
         try:
             date(2020, int(wiz.fiscalyear_last_month),
                  wiz.fiscalyear_last_day)
         except ValueError:
             raise ValidationError(
                 _('Incorrect fiscal year date: day is out of range for month. Month: %s; Day: %s'
                   ) % (wiz.fiscalyear_last_month, wiz.fiscalyear_last_day))
Esempio n. 12
0
 def _check_mother_tongue(self):
     if self.mother_tongue and self.employee_id:
         language_rec = self.search(
             [('employee_id', '=', self.employee_id.id),
              ('mother_tongue', '=', True), ('id', '!=', self.id)],
             limit=1)
         if language_rec:
             raise ValidationError(
                 _("If you want to set '%s' \
                 as a mother tongue, first you have to uncheck mother \
                 tongue in '%s' language.") %
                 (self.language, language_rec.language))
Esempio n. 13
0
 def _check_afip_configurations(self):
     """ Do not let the user update the journal if it already contains confirmed invoices """
     journals = self.filtered(lambda x: x.company_id.country_id.code == "AR"
                              and x.type in ['sale', 'purchase'])
     invoices = self.env['account.move'].search(
         [('journal_id', 'in', journals.ids), ('posted_before', '=', True)],
         limit=1)
     if invoices:
         raise ValidationError(
             _("You can not change the journal's configuration if it already has validated invoices"
               ) + ' (' +
             ', '.join(invoices.mapped('journal_id').mapped('name')) + ')')
Esempio n. 14
0
 def action_cancel(self):
     for rec in self:
         for attendee in rec.attendees_ids:
             if attendee.state not in [
                     'draft', 'awaiting_training_start', 'in_complete'
             ]:
                 raise ValidationError(
                     _("You can not cancel the Training Class if \
                         all attendees are not in Draft, Awaiting \
                         Training Start or In complete state!"))
     self.write({'state': 'cancel'})
     return True
Esempio n. 15
0
 def _check_deposit(self):
     for deposit in self:
         deposit_currency = deposit.currency_id
         if deposit_currency == deposit.company_id.currency_id:
             for line in deposit.check_payment_ids:
                 if line.currency_id:
                     raise ValidationError(
                         _("The check with amount %s and reference '%s' "
                           "is in currency %s but the deposit is in "
                           "currency %s.") %
                         (line.debit, line.ref or '', line.currency_id.name,
                          deposit_currency.name))
         else:
             for line in deposit.check_payment_ids:
                 if line.currency_id != deposit_currency:
                     raise ValidationError(
                         _("The check with amount %s and reference '%s' "
                           "is in currency %s but the deposit is in "
                           "currency %s.") %
                         (line.debit, line.ref or '', line.currency_id.name,
                          deposit_currency.name))
Esempio n. 16
0
 def print_report(self):
     start_date = fields.Date.from_string(self.start_date)
     end_date = fields.Date.from_string(self.end_date)
     if start_date > end_date:
         raise ValidationError(
             _("End Date cannot be set before \
         Start Date."))
     else:
         data = self.read(['course_id', 'start_date', 'end_date'])[0]
         return self.env.ref(
             'openeducat_admission.action_report_report_admission_analysis') \
             .report_action(self, data=data)
Esempio n. 17
0
 def _check_postal_num(self):
     """Validate postal number format"""
     for rec in self:
         if rec.l10n_ch_postal and not _is_l10n_ch_postal(
                 rec.l10n_ch_postal):
             # l10n_ch_postal is used for the purpose of Client Number on your own accounts, so don't do the check there
             if rec.partner_id and not rec.partner_id.ref_company_ids:
                 raise ValidationError(
                     _("The postal number {} is not valid.\n"
                       "It must be a valid postal number format. eg. 10-8060-7"
                       ).format(rec.l10n_ch_postal))
     return True
Esempio n. 18
0
 def _check_negatives(self):
     values = self.read([
         "mrp_minimum_order_qty",
         "mrp_maximum_order_qty",
         "mrp_qty_multiple",
         "mrp_minimum_stock",
         "mrp_nbr_days",
         "group_estimate_days",
     ])
     for rec in values:
         if any(v < 0 for v in rec.values()):
             raise ValidationError(_("You cannot use a negative number."))
Esempio n. 19
0
 def _alias_is_ascii(self):
     """ The local-part ("display-name" <local-part@domain>) of an
         address only contains limited range of ascii characters.
         We DO NOT allow anything else than ASCII dot-atom formed
         local-part. Quoted-string and internationnal characters are
         to be rejected. See rfc5322 sections 3.4.1 and 3.2.3
     """
     if any(alias.alias_name and not dot_atom_text.match(alias.alias_name)
            for alias in self):
         raise ValidationError(
             _("You cannot use anything else than unaccented latin characters in the alias address."
               ))
Esempio n. 20
0
    def post(self):
        """ Create the journal items for the payment and update the payment's state to 'posted'.
            A journal entry is created containing an item in the source liquidity account (selected journal's default_debit or default_credit)
            and another in the destination reconciliable account (see _compute_destination_account_id).
            If invoice_ids is not empty, there will be one reconciliable move line per invoice to reconcile with.
            If the payment is a transfer, a second journal entry is created in the destination journal to receive money from the transfer account.
        """
        for rec in self:

            if rec.state != 'draft':
                raise UserError(_("Only a draft payment can be posted."))

            if any(inv.state != 'open' for inv in rec.invoice_ids):
                raise ValidationError(
                    _("The payment cannot be processed because the invoice is not open!"
                      ))

            # Use the right sequence to set the name
            if rec.payment_type == 'transfer':
                sequence_code = 'account.payment.transfer'
            else:
                if rec.partner_type == 'customer':
                    if rec.payment_type == 'inbound':
                        sequence_code = 'account.payment.customer.invoice'
                    if rec.payment_type == 'outbound':
                        sequence_code = 'account.payment.customer.refund'
                if rec.partner_type == 'supplier':
                    if rec.payment_type == 'inbound':
                        sequence_code = 'account.payment.supplier.refund'
                    if rec.payment_type == 'outbound':
                        sequence_code = 'account.payment.supplier.invoice'
            rec.name = self.env['ir.sequence'].with_context(
                ir_sequence_date=rec.payment_date).next_by_code(sequence_code)
            if not rec.name and rec.payment_type != 'transfer':
                raise UserError(
                    _("You have to define a sequence for %s in your company.")
                    % (sequence_code, ))

            # Create the journal entry
            amount = rec.amount * (rec.payment_type in ('outbound', 'transfer')
                                   and 1 or -1)
            move = rec._create_payment_entry(amount)

            # In case of a transfer, the first journal entry created debited the source liquidity account and credited
            # the transfer account. Now we debit the transfer account and credit the destination liquidity account.
            if rec.payment_type == 'transfer':
                transfer_credit_aml = move.line_ids.filtered(
                    lambda r: r.account_id == rec.company_id.
                    transfer_account_id)
                transfer_debit_aml = rec._create_transfer_entry(amount)
                (transfer_credit_aml + transfer_debit_aml).reconcile()

            rec.write({'state': 'posted', 'move_name': move.name})
Esempio n. 21
0
    def _check_leave_type_validity(self):
        for allocation in self:
            if allocation.holiday_status_id.validity_stop:
                vstop = allocation.holiday_status_id.validity_stop
                today = fields.Date.today()

                if vstop < today:
                    raise ValidationError(
                        _('You can allocate %(allocation_type)s only before %(date)s.',
                          allocation_type=allocation.holiday_status_id.
                          display_name,
                          date=allocation.holiday_status_id.validity_stop))
Esempio n. 22
0
    def record_production(self):
        if (self.qty_producing + self.qty_produced) > self.qty_ready_prod:
            raise ValidationError(
                _('It is not possible to produce more that %s') %
                self.qty_ready_prod)
        res = super(MrpWorkorder, self).record_production()

        # se verifica daca se poate inchide comanda
        if self.production_id.check_to_done:
            self.production_id.button_mark_done()

        return res
Esempio n. 23
0
 def export_to_qbo(self):
     """Create account tax and tax rate in QBO"""
     #         company = self.env['res.users'].search([('id','=',self._uid)],limit=1).company_id
     acc_taxes = self.env['account.tax'].browse(
         self._context.get('active_ids'))
     for tax in acc_taxes:
         if tax.amount_type == 'group':
             tax.export_tax_code_to_qbo()
         else:
             raise ValidationError(
                 _('''Tax Computation - Group of Taxes exported to QBO with their multiple tax rate.
             Individual tax rate export API's is not available.'''))
Esempio n. 24
0
 def _check_payment_method_receivable_accounts(self):
     # This is normally not supposed to happen to have a payment method without a receivable account set,
     # as this is a required field. However, it happens the receivable account cannot be found during upgrades
     # and this is a bommer to block the upgrade for that point, given the user can correct this by himself,
     # without requiring a manual intervention from our upgrade support.
     # However, this must be ensured this receivable is well set before opening a POS session.
     invalid_payment_methods = self.payment_method_ids.filtered(lambda method: not method.receivable_account_id)
     if invalid_payment_methods:
         method_names = ", ".join(method.name for method in invalid_payment_methods)
         raise ValidationError(
             _("You must configure an intermediary account for the payment methods: %s.") % method_names
         )
Esempio n. 25
0
 def write(self, vals):
     res = super(CRMLeadScore, self).write(vals)
     if 'profile_scoring_type' in vals:
         same_records = self.search([
             ('id', '!=', self.id),
             ('profile_scoring_type', '=', vals['profile_scoring_type'])
         ])
         if same_records:
             raise ValidationError(_(
                 "There's already one rule defined for '%s' type!") %
                 str(self.TYPES[self.profile_scoring_type]))
     return res
Esempio n. 26
0
 def write(self, vals):
     if vals.get('active') is False:
         # DLE: It should not be necessary to modify this to make work the ORM. The problem was just the recompute
         # of partner.user_ids when you create a new user for this partner, see test test_70_archive_internal_partners
         # You modified it in a previous commit, see original commit of this:
         # https://github.com/flectra/flectra/commit/9d7226371730e73c296bcc68eb1f856f82b0b4ed
         #
         # RCO: when creating a user for partner, the user is automatically added in partner.user_ids.
         # This is wrong if the user is not active, as partner.user_ids only returns active users.
         # Hence this temporary hack until the ORM updates inverse fields correctly.
         self.invalidate_cache(['user_ids'], self._ids)
         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 'company_id' in vals:
         company_id = vals['company_id']
         for partner in self:
             if company_id and partner.user_ids:
                 company = self.env['res.company'].browse(company_id)
                 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)"
                     ))
             if partner.child_ids:
                 partner.child_ids.write({'company_id': company_id})
     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.su:
         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
Esempio n. 27
0
 def _check_project_and_template(self):
     """ NOTE 'service_tracking' should be in decorator parameters but since ORM check constraints twice (one after setting
         stored fields, one after setting non stored field), the error is raised when company-dependent fields are not set.
         So, this constraints does cover all cases and inconsistent can still be recorded until the ORM change its behavior.
     """
     for product in self:
         if product.service_tracking == 'no' and (
                 product.project_id or product.project_template_id):
             raise ValidationError(
                 _('The product %s should not have a project nor a project template since it will not generate project.'
                   ) % (product.name, ))
         elif product.service_tracking == 'task_global_project' and product.project_template_id:
             raise ValidationError(
                 _('The product %s should not have a project template since it will generate a task in a global project.'
                   ) % (product.name, ))
         elif product.service_tracking in [
                 'task_in_project', 'project_only'
         ] and product.project_id:
             raise ValidationError(
                 _('The product %s should not have a global project since it will generate a project.'
                   ) % (product.name, ))
Esempio n. 28
0
 def _check_eco_admin_index(self):
     for record in self:
         if not record.l10n_it_has_eco_index:
             continue
         if not record.l10n_it_eco_index_office\
            or not record.l10n_it_eco_index_number\
            or not record.l10n_it_eco_index_share_capital\
            or not record.l10n_it_eco_index_sole_shareholder\
            or not record.l10n_it_eco_index_liquidation_state:
             raise ValidationError(
                 _("All fields about the Economic and Administrative Index must be completed."
                   ))
Esempio n. 29
0
    def _check_answer_type_skipped(self):
        for line in self:
            if (line.skipped == bool(line.answer_type)):
                raise ValidationError(
                    _('A question can either be skipped or answered, not both.'
                      ))

            # allow 0 for numerical box
            if line.answer_type == 'numerical_box' and float_is_zero(
                    line['value_numerical_box'], precision_digits=6):
                continue
            if line.answer_type == 'suggestion':
                field_name = 'suggested_answer_id'
            elif line.answer_type:
                field_name = 'value_%s' % line.answer_type
            else:  # skipped
                field_name = False

            if field_name and not line[field_name]:
                raise ValidationError(
                    _('The answer must be in the right type'))
Esempio n. 30
0
 def _verify_request_recaptcha_token(self, action):
     """ Verify the recaptcha token for the current request.
         If no recaptcha private key is set the recaptcha verification
         is considered inactive and this method will return True.
     """
     ip_addr = request.httprequest.remote_addr
     token = request.params.pop('recaptcha_token_response', False)
     recaptcha_result = request.env['ir.http']._verify_recaptcha_token(
         ip_addr, token, action)
     if recaptcha_result in ['is_human', 'no_secret']:
         return True
     if recaptcha_result == 'wrong_secret':
         raise ValidationError(_("The reCaptcha private key is invalid."))
     elif recaptcha_result == 'wrong_token':
         raise ValidationError(_("The reCaptcha token is invalid."))
     elif recaptcha_result == 'timeout':
         raise UserError(_("Your request has timed out, please retry."))
     elif recaptcha_result == 'bad_request':
         raise UserError(_("The request is invalid or malformed."))
     else:
         return False