def action_exclude(self): orig_ids, dupl_ids = self.get_origin_duplicate_ids() if dupl_ids: raise api.Warning(u"Нельзя исключать Дубликаты") for rec in self: rec.self_id.child_ids.write({'parent_id': rec.parent_id.id}) rec.unlink()
def unlink(self): for line in self: if line.state != 'draft': raise api.Warning( _('You are not allowed to delete a credit control ' 'line that is not in draft state.') ) return super(CreditControlLine, self).unlink()
def _check_run_date(self, controlling_date): """ Ensure that there is no credit line in the future using controlling_date """ runs = self.search([('date', '>', controlling_date)], order='date DESC', limit=1) if runs: raise api.Warning(_('A run has already been executed more ' 'recently than %s') % (runs.date)) line_obj = self.env['credit.control.line'] lines = line_obj.search([('date', '>', controlling_date)], order='date DESC', limit=1) if lines: raise api.Warning(_('A credit control line more ' 'recent than %s exists at %s') % (controlling_date, lines.date))
def email_invoices(self): self.ensure_one() if not self.invoice_ids: raise api.Warning(_('No Invoice selected.')) self.invoice_ids.with_context( active_model='account.invoice', active_ids=self.invoice_ids.ids)._generate_emails( self.email_template_id) return {'type': 'ir.actions.act_window_close'}
def email_lines(self): self.ensure_one() if not self.line_ids: raise api.Warning(_('No credit control lines selected.')) comm_obj = self.env['credit.control.communication'] filtered_lines = self._filter_lines(self.line_ids) comms = comm_obj._generate_comm_from_credit_lines(filtered_lines) comms._generate_emails() return {'type': 'ir.actions.act_window_close'}
def check_policy_against_account(self, account): """ Ensure that the policy corresponds to account relation """ policies = self.search([]) allowed = [x for x in policies if account in x.account_ids or x.do_nothing] if self not in allowed: allowed_names = u"\n".join(x.name for x in allowed) raise api.Warning( _('You can only use a policy set on ' 'account %s.\n' 'Please choose one of the following ' 'policies:\n %s') % (account.name, allowed_names) ) return True
def find(self): """ Search for fields that cannot be instantiated. """ res = [] cr = self.env.cr cr.execute("SELECT model, name from ir_model_fields") for model, name in cr.fetchall(): Model = self.pool.get(model) if not Model or name not in Model._fields: res.append((0, 0, {'name': name, 'model': model})) if not res: raise api.Warning(u"Не найдены Поля для удаления") return res
def mark_lines(self): """ Write state of selected credit lines to the one in entry done credit line will be ignored """ self.ensure_one() if not self.line_ids: raise api.Warning(_('No credit control lines selected.')) filtered_lines = self._filter_lines(self.line_ids) if not filtered_lines: raise api.Warning( _('No lines will be changed. ' 'All the selected lines are already done.')) self._mark_lines(filtered_lines, self.name) return { 'domain': unicode([('id', 'in', filtered_lines.ids)]), 'view_type': 'form', 'view_mode': 'tree,form', 'view_id': False, 'res_model': 'credit.control.line', 'type': 'ir.actions.act_window' }
def _generate_credit_lines(self): """ Generate credit control lines. """ self.ensure_one() cr_line_obj = self.env['credit.control.line'] move_line_obj = self.env['account.move.line'] manually_managed_lines = move_line_obj.browse() self._check_run_date(self.date) policies = self.policy_ids if not policies: raise api.Warning(_('Please select a policy')) report = '' generated = cr_line_obj.browse() for policy in policies: if policy.do_nothing: continue lines = policy._get_move_lines_to_process(self.date) manual_lines = policy._lines_different_policy(lines) lines -= manual_lines manually_managed_lines |= manual_lines policy_lines_generated = cr_line_obj.browse() if lines: # policy levels are sorted by level # so iteration is in the correct order create = cr_line_obj.create_or_update_from_mv_lines for level in reversed(policy.level_ids): level_lines = level.get_level_lines(self.date, lines) policy_lines_generated += create(level_lines, level, self.date) generated |= policy_lines_generated if policy_lines_generated: report += (_("Policy \"<b>%s</b>\" has generated <b>%d Credit " "Control Lines.</b><br/>") % (policy.name, len(policy_lines_generated))) else: report += _( "Policy \"<b>%s</b>\" has not generated any " "Credit Control Lines.<br/>" % policy.name ) vals = {'state': 'done', 'report': report, 'manual_ids': [(6, 0, manually_managed_lines.ids)], 'line_ids': [(6, 0, generated.ids)]} self.write(vals) return generated
def print_lines(self): self.ensure_one() comm_obj = self.env['credit.control.communication'] if not self.line_ids: raise api.Warning(_('No credit control lines selected.')) lines = self._get_lines(self.line_ids, self._credit_line_predicate) comms = comm_obj._generate_comm_from_credit_lines(lines) if self.mark_as_sent: comms._mark_credit_line_as_sent() report_name = 'account_credit_control.report_credit_control_summary' report_obj = self.env['report'].with_context(active_ids=comms.ids) return report_obj.get_action(comms, report_name)
def generate_credit_lines(self): """ Generate credit control lines Lock the ``credit_control_run`` Postgres table to avoid concurrent calls of this method. """ try: self.env.cr.execute('SELECT id FROM credit_control_run' ' LIMIT 1 FOR UPDATE NOWAIT') except Exception: # In case of exception openerp will do a rollback # for us and free the lock raise api.Warning(_('A credit control run is already running' ' in background, please try later.')) self._generate_credit_lines() return True
def action_cancel(self): """Prevent to cancel invoice related to credit line""" # We will search if this invoice is linked with credit cc_line_obj = self.env['credit.control.line'] for invoice in self: nondraft_domain = [('invoice_id', '=', invoice.id), ('state', '!=', 'draft')] cc_nondraft_lines = cc_line_obj.search(nondraft_domain) if cc_nondraft_lines: raise api.Warning( _('You cannot cancel this invoice.\n' 'A payment reminder has already been ' 'sent to the customer.\n' 'You must create a credit note and ' 'issue a new invoice.')) draft_domain = [('invoice_id', '=', invoice.id), ('state', '=', 'draft')] cc_draft_line = cc_line_obj.search(draft_domain) cc_draft_line.unlink() return super(AccountInvoice, self).action_cancel()
def action_next(self): credit_line_obj = self.env['credit.control.line'] controlling_date = self._context['default_date'] partner_id = self._context['default_partner_id'] ref = self._context['active_id'] if not self.policy_id.account_ids: raise api.Warning( _('You can only use a policy set on ' 'account \n' 'Please choose one of the following ' 'policies:\n')) return {'type': 'ir.actions.act_window_close'} vals = [] amount_total = self._context['default_amount_due'] all_amount_total = 0.0 for account in self.policy_id.account_ids: all_amount_total += amount_total vals.append((0, False, { 'date': controlling_date, 'ref': ref, 'name': _("Agree temporary permit"), 'account_id': account.id, 'credit': ((amount_total < 0) and -amount_total) or 0.0, 'debit': ((amount_total > 0) and amount_total) or 0.0, })) move_id = self._create_account_move_line(controlling_date, ref, partner_id, all_amount_total, vals) amount_due = sum([x.amount_due for x in self.credit_control_line_ids]) create = credit_line_obj.create_or_update_from_mv_lines generated_lines = create(move_id, self.new_policy_level_id, controlling_date, check_tolerance=False) generated_lines.write({ 'amount_due': -amount_due, 'state': 'temporary_permit' }) #self._set_so_policy(self.move_line_ids, self.new_policy_id) return {'type': 'ir.actions.act_window_close'}
def add_tasks(self): if not self.project: raise api.Warning('Project not specified') self.project.add_tasks(self.tasks)
def unlink(self): for rec in self: if rec.state != 'draft': raise api.Warning(_("You can only delete a 'not processed' line.")) return super(StockWarehouseUser, self).unlink()