def validation_poldocument_dni(self): _logger.info('----------') _logger.info(self.documenttype) if self.documenttype in ['D','C','I']: validcaracter = "TRWAGMYFPDXBNJZSQVHLCKE" dig_ext = "XYZ" reemp_dig_ext = {'X':'0', 'Y':'1', 'Z':'2'} numeros = "1234567890" dni = self.poldocument.upper() _logger.info(dni) if len(dni) == 9: dig_control = dni[8] dni = dni[:8] _logger.info('Control es') _logger.info(dig_control) if dni[0] in dig_ext: _logger.info('extranjero empieza por XYZ') dni = dni.replace(dni[0], reemp_dig_ext[dni[0]]) _logger.info(dni) if (len(dni) == len([n for n in dni if n in numeros])) and (validcaracter[int(dni)%23] == dig_control): _logger.info('Esta O.K.') else: raise models.ValidationError('DNI/NIE erroneo reviselo') else: raise models.ValidationError('DNI/NIE longitud erronea formato correcto: (12345678A o X1234567A)') _logger.info('----------')
def _check_loan_period(self): for loan in self: if loan.manual_loan_period <= 0: strWarning = _("Loan period has to be greated than 0") raise models.ValidationError(strWarning) if loan.manual_loan_period > loan.maximum_installment_period: strWarning = _("Loan period exceed maximum installment period") raise models.ValidationError(strWarning)
def _check_loan_amount(self): for loan in self: if loan.loan_amount <= 0.0: strWarning = _("Loan amount has to be greater than 0") raise models.ValidationError(strWarning) if loan.loan_amount > loan.maximum_loan_amount: strWarning = _("Loan amount exceed maximum loan amount") raise models.ValidationError(strWarning)
def _check_product(self): for line in self: if line.expense_id.required_expense_product: if not line.product_id: strWarning = _("Product has to be filled") raise models.ValidationError(strWarning) emp = line.expense_id.employee_id product_ids = emp.all_allowed_expense_product_ids.ids if line.product_id and line.expense_id.limit_product_selection: if line.product_id.id not in product_ids: strWarning = _("Product is not allowed") raise models.ValidationError(strWarning)
def _check_close_with_evaluation(self): for nc in self: if nc.state == 'done': if not nc.evaluation_comments: raise models.ValidationError( _("Evaluation Comments are required " "in order to close a Nonconformity.")) actions_are_closed = (x.stage_id.is_ending for x in nc._get_all_actions()) if not all(actions_are_closed): raise models.ValidationError( _("All actions must be done " "before closing a Nonconformity."))
def _check_max_rooms(self): warning_msg = "" for r in self: if self.max_real_rooms > self.total_rooms_count: warning_msg += _('The Maxime rooms allowed can not be greate \ than total rooms count') raise models.ValidationError(warning_msg)
def get_rate(self, ptkp_category): self.ensure_one() lines = self.line_ids.filtered( lambda r: r.ptkp_category_id.id == ptkp_category.id) if not lines: raise models.ValidationError(_("Wes")) return lines[0].ptkp_rate
def validation_under_age(self): from datetime import datetime, timedelta years = str(datetime.now().date() - timedelta(days=365*16+4)) limit_date = datetime.strptime(years, "%Y-%m-%d") birth_date = datetime.strptime(self.birthdate_date, '%Y-%m-%d') if limit_date < birth_date: raise models.ValidationError( 'The client is under 16 years old. Data collection is not performed for those born before %s.' % (years))
def find(self, dt=None): if not dt: dt = datetime.now().strftime("%Y-%m-%d") criteria = [("date_start", "<=", dt)] results = self.search(criteria, limit=1) if not results: strWarning = _("No biaya jabatan configuration for %s" % dt) raise models.ValidationError(strWarning) return results[0]
def action_cancel(self): for loan in self: if not loan._can_cancel(): strWarning = _("Loan can only be cancelled on " "draft, waiting for approval or " "ready to be process state") raise models.ValidationError(strWarning) loan._delete_receivable_move() data = loan._prepare_cancel_data() loan.write(data)
def _check_duplicated_rooms(self): warning_msg = "" for r in self: room_categories = self.room_type_ids.mapped('cat_id.id') if self.room_ids & self.env['hotel.room'].search( [('categ_id.id', 'in', room_categories)]): room_ids = self.room_ids & self.env['hotel.room'].search( [('categ_id.id', 'in', room_categories)]) rooms_name = ','.join(str(x.name) for x in room_ids) warning_msg += 'You can not enter the same room in duplicate (check the room types) %s' % rooms_name raise models.ValidationError(warning_msg)
def _find_period(self, dt=None): if not dt: dt = datetime.now().strftime("%Y-%m-%d") criteria = [ ("date_start", "<=", dt), ("date_end", ">=", dt), ] results = self.search(criteria) if not results: strWarning = _("No DJBC report period configured for %s" % dt) raise models.ValidationError(strWarning) result = results[0] return result
def _check_release_date(self): for r in self: if r.fine_operazioni is not False and r.fine_operazioni < r.inizio_operazioni: raise models.ValidationError( 'La Data di Consegna deve essere successiva alla data di Inizio Operazioni!' )
def _check_hierarchy(self): if not self._check_recursion(): raise models.ValidationError( 'Error! You cannot create recursive categories.')
def _check_date_release(self): for r in self: if r.date_release > dt.today(): raise models.ValidationError('Release date cannot be in future.')
def send_invoice(self): self.ensure_one() if self.is_tax_exempt == 'no' and self.tax == 0: raise models.ValidationError( "Por favor ingresa el valor de impuesto >0") # default_currency=self.env['res.currency'].search([('name','=',self.money.upper())]) default_clp = self.env['res.currency'].search([('name', '=', 'CLP')]) values = { 'company_id': self.company_id.id, 'client_id': self.client_id.id, 'project_id': self.project_id.id, 'projection_id': self.projection_id.id, 'hes': self.hes, 'contract': self.contract, 'oc': self.oc, 'glosa': self.glosa, 'amount': self.amount, 'is_tax_exempt': self.is_tax_exempt, 'tax': self.tax, 'money': self.money, 'clp_id': default_clp.id, 'uf_value': self.uf_value, 'dolar_value': self.dolar_value, 'total_clp': self.total_clp, 'emission_date': self.emission_date, 'projection_status': self.pre_invoice_state, 'document_type': self.document_type.id, 'document_number': self.document_number, 'invoice_product_id': self.env['product.product'].search([('id', '=', '1')]).id, 'invoice_account_id': self.env['account.account'].search([('id', '=', '3635')]).id, 'invoice_account_receivable_id': self.env['account.account'].search([('id', '=', '1239')]).id } lines_list = [] lvalues = {} sequence = 1 # find period id from emission date period_obj = self.env['account.period'] period_id = period_obj.search([('date_start', '<=', self.emission_date), ('date_stop', '>=', self.emission_date), ('company_id', '=', self.company_id.id), ('special', '=', False)]) lvalues = {} lvalues['projection_id'] = self.projection_id.id lvalues['sequence'] = sequence lvalues['name'] = self.glosa lvalues['currency_id'] = self.currency_id.id lvalues['company_id'] = self.company_id.id lvalues['period_id'] = period_id.id lvalues['quantity'] = 1 lvalues['amount'] = self.amount lvalues['amount_clp'] = self.total_clp lvalues['product_id'] = self.env['product.product'].search([('id', '=', '1')]).id lvalues['account_id'] = self.env['account.account'].search([ ('id', '=', '3635') ]).id if self.is_tax_exempt == 'no': lvalues['taxes_id'] = [(4, 1)] lines_list.append((0, 0, lvalues)) sequence += 1 values['line_ids'] = lines_list res = self.env['account.pre_invoice'].create(values) res.amount = self.amount res.total_clp = self.total_clp res.currency_id = self.env['res.currency'].search([ ('name', '=', str(self.money).upper()) ]).id res.send_date = fields.Date.today() if not res: raise AssertionError("No se pudo ingresar la factura.") else: self.projection_id.write({'state': 'preinvoiced'})
def action_send(self): self.ensure_one() if self.is_tax_exempt == 'no' and self.tax == 0: raise models.ValidationError( "Por favor ingresa el valor de impuesto >0") values = { 'company_id': self.company_id.id, 'client_id': self.partner_id.id, 'project_id': self.project_id.id, 'invoice_account_receivable_id': self.partner_id.property_account_receivable.id or False, 'hes': self.hes, 'contract': self.contract, 'oc': self.oc, 'glosa': self.glosa, 'money': self.money, 'is_tax_exempt': self.is_tax_exempt, 'tax': self.tax, 'currency_id': self.currency_id.id, 'clp_id': self.clp_id.id, 'uf_value': self.uf_value, 'dolar_value': self.dolar_value, 'total_clp': self.total_clp, 'emission_date': self.emission_date, 'document_type': self.document_type.id, 'send_date': self.send_date, 'projection_status': 'pendiente', 'invoice_product_id': self.env['product.product'].search([('id', '=', '1')]).id, 'invoice_account_id': self.env['account.account'].search([('id', '=', '3635')]).id, 'invoice_account_receivable_id': self.env['account.account'].search([('id', '=', '1239')]).id } # create lines for Prefactura lines_list = [] lvalues = {} sequence = 1 for line in self.line_ids: lvalues = {} temp_clp = 0 # here we need to calculate the amounts if self.currency_id.name == 'USD': temp_clp = round(self.dolar_value * float(line.line_amount)) elif self.currency_id.name == 'UF': temp_clp = round(self.uf_value * float(line.line_amount)) elif self.currency_id.name == 'CLP': temp_clp = float(line.line_amount) lvalues['sequence'] = sequence lvalues['name'] = line.outsourcing_id.name lvalues['outsourcing_id'] = line.outsourcing_id.id lvalues['currency_id'] = line.currency_id.id lvalues['company_id'] = line.company_id.id lvalues['period_id'] = line.period_id.id lvalues['quantity'] = line.quantity lvalues['amount'] = line.line_amount lvalues['amount_clp'] = temp_clp lines_list.append((0, 0, lvalues)) sequence += 1 values['line_ids'] = lines_list res = self.env['account.pre_invoice'].create(values) if not res: raise AssertionError("No se pudo ingresar la factura.") else: for line in self.line_ids: line.outsourcing_id.write({'state': 'preinvoiced'})
def compute_pph_21_2110001( self, bulan_bergabung=1, tanggal_pemotongan=False, gaji=0.0, tunjangan_pph=0.0, tunjangan_lain=0.0, jumlah_penghasilan_non_rutin=0.0, pensiun=0.0, ): self.ensure_one() result = { "biaya_jabatan_rutin": 0.0, "biaya_jabatan_non_rutin": 0.0, "biaya_jabatan": 0.0, "pengurang": 0.0, "penghasilan_bruto_rutin_setahun": 0.0, "penghasilan_bruto_non_rutin_setahun": 0.0, "penghasilan_bruto_setahun": 0.0, "ptkp": 0.0, "pkp_rutin_setahun": 0.0, "pkp_setahun": 0.0, "pph_rutin_setahun": 0.0, "pph_non_rutin_setahun": 0.0, "pph_setahun": 0.0, "pph": 0.0, } ptkp_category = self.ptkp_category_id if not ptkp_category: raise models.ValidationError( _("Partner's PTKP Category is not configured")) jumlah_penghasilan_rutin = gaji + \ tunjangan_pph + tunjangan_lain obj_biaya_jabatan = self.env["l10n_id.pph_21_biaya_jabatan"] perhitungan_biaya_jabatan = obj_biaya_jabatan.find( tanggal_pemotongan).get_biaya_jabatan( jumlah_penghasilan_rutin, jumlah_penghasilan_non_rutin, tanggal_pemotongan, ) biaya_jabatan_rutin = perhitungan_biaya_jabatan["biaya_jabatan_rutin"] biaya_jabatan_non_rutin = perhitungan_biaya_jabatan[ "biaya_jabatan_non_rutin"] biaya_jabatan = perhitungan_biaya_jabatan["biaya_jabatan"] pengurang = biaya_jabatan_rutin + \ biaya_jabatan_non_rutin + \ pensiun netto_rutin = jumlah_penghasilan_rutin - \ biaya_jabatan_rutin - \ pensiun netto_non_rutin = jumlah_penghasilan_non_rutin - \ biaya_jabatan_non_rutin netto = netto_rutin + netto_non_rutin netto_setahun_rutin = netto_rutin * (13 - bulan_bergabung) netto_setahun = netto_setahun_rutin + netto_non_rutin if gaji > 0.0: ptkp = ptkp_category.get_rate(tanggal_pemotongan) else: ptkp = 0.0 pkp = netto_setahun - ptkp pkp_rutin = netto_setahun_rutin - ptkp obj_pph = self.env["l10n_id.pph_21_rate"] pph_setahun = obj_pph.find(tanggal_pemotongan).compute_tax(pkp) pph_setahun_rutin = obj_pph.find(tanggal_pemotongan).compute_tax( pkp_rutin) pph_non_rutin = pph_setahun - pph_setahun_rutin pph_sebulan = pph_setahun_rutin / (13 - bulan_bergabung) pph = pph_sebulan + pph_non_rutin npwp = self.vat and len(self.vat) > 0 or False if not npwp: obj_multiplier = self.env["l10n_id.pph_21_npwp_rate_modifier"] pph = (obj_multiplier.get_rate(tanggal_pemotongan) / 100.00) * pph pph = float(int(pph)) result["biaya_jabatan_rutin"] = biaya_jabatan_rutin result["biaya_jabatan_non_rutin"] = biaya_jabatan_non_rutin result["biaya_jabatan"] = biaya_jabatan result["pengurang"] = pengurang result["netto"] = netto result["netto_setahun"] = netto_setahun result["ptkp"] = ptkp result["pkp"] = pkp result["pph_setahun"] = pph_setahun result["pph"] = pph return result
def validation_dates(self): if self.exit_date < self.enter_date: raise models.ValidationError( _('Departure date (%s) is prior to arrival on %s') % (self.exit_date, self.enter_date))
def compute_pph_21_2110001( self, period_amount=1, tanggal_pemotongan=False, gaji=0.0, tunjangan_pph=0.0, tunjangan_lain=0.0, jumlah_penghasilan_non_rutin=0.0, pensiun=0.0, jht=0.0, ): self.ensure_one() result = { "biaya_jabatan_rutin": 0.0, "biaya_jabatan_non_rutin": 0.0, "biaya_jabatan": 0.0, "pengurang": 0.0, "penghasilan_bruto_rutin_setahun": 0.0, "penghasilan_bruto_non_rutin_setahun": 0.0, "penghasilan_bruto_setahun": 0.0, "ptkp": 0.0, "pkp_rutin_setahun": 0.0, "pkp_setahun": 0.0, "pph_rutin_setahun": 0.0, "pph_non_rutin_setahun": 0.0, "pph_setahun": 0.0, "pph": 0.0, "pph_ta": 0.0, } ptkp_category = self.ptkp_category_id if not ptkp_category: raise models.ValidationError( _("Partner's PTKP Category is not configured")) jumlah_penghasilan_rutin = gaji + \ tunjangan_pph + tunjangan_lain bruto_rutin_setahun = jumlah_penghasilan_rutin * period_amount bruto_non_rutin_setahun = bruto_rutin_setahun + jumlah_penghasilan_non_rutin obj_biaya_jabatan = self.env["l10n_id.pph_21_biaya_jabatan"] try: obj_biaya_jabatan_id = obj_biaya_jabatan.find(tanggal_pemotongan) perhitungan_biaya_jabatan = obj_biaya_jabatan.find( tanggal_pemotongan).get_biaya_jabatan( bruto_rutin_setahun, jumlah_penghasilan_non_rutin, period_amount, ) biaya_jabatan_rutin = perhitungan_biaya_jabatan[ "biaya_jabatan_rutin"] biaya_jabatan_non_rutin = perhitungan_biaya_jabatan[ "biaya_jabatan_non_rutin"] except: biaya_jabatan_rutin = 0.0 biaya_jabatan_non_rutin = 0.0 # biaya_jabatan = perhitungan_biaya_jabatan["biaya_jabatan"] pengurang_rutin_setahun = biaya_jabatan_rutin + pensiun * period_amount + jht * period_amount pengurang_non_rutin_setahun = biaya_jabatan_non_rutin + pensiun * period_amount + jht * period_amount neto_rutin_setahun = bruto_rutin_setahun - pengurang_rutin_setahun neto_non_rutin_setahun = bruto_non_rutin_setahun - pengurang_non_rutin_setahun if gaji > 0.0: ptkp = ptkp_category.get_rate(tanggal_pemotongan) else: ptkp = 0.0 pkp_rutin_setahun = neto_rutin_setahun - ptkp pkp_non_rutin_setahun = neto_non_rutin_setahun - ptkp obj_pph = self.env["l10n_id.pph_21_rate"] pph_setahun_rutin = obj_pph.find(tanggal_pemotongan).compute_tax( pkp_rutin_setahun) pph_setahun_non_rutin = obj_pph.find(tanggal_pemotongan).compute_tax( pkp_non_rutin_setahun) npwp = self.npwp or False if not npwp: obj_multiplier = self.env["l10n_id.pph_21_npwp_rate_modifier"] pph_setahun_rutin = (obj_multiplier.get_rate(tanggal_pemotongan) / 100.00) * pph_setahun_rutin pph_setahun_non_rutin = ( obj_multiplier.get_rate(tanggal_pemotongan) / 100.00) * pph_setahun_non_rutin pph_setahun_rutin = float(int(pph_setahun_rutin)) pph_setahun_non_rutin = float(int(pph_setahun_non_rutin)) pph_non_rutin = pph_setahun_non_rutin - pph_setahun_rutin pph_rutin = pph_setahun_rutin / period_amount pph = pph_rutin + pph_non_rutin # hitung pph tenaga ahli dpp = gaji / 2 pkp_ta = dpp - ptkp / 12 akumulasi_pkp_ta = pkp_ta * period_amount obj_pph = self.env["l10n_id.pph_21_rate"] pph_ta_rate = obj_pph.find(tanggal_pemotongan).compute_rate( akumulasi_pkp_ta) pph_ta = pkp_ta * pph_ta_rate / 100 result["biaya_jabatan_rutin"] = biaya_jabatan_rutin result["biaya_jabatan_non_rutin"] = biaya_jabatan_non_rutin # result["biaya_jabatan"] = biaya_jabatan # result["pengurang"] = pengurang # result["netto"] = netto # result["netto_setahun"] = netto_setahun result["ptkp"] = ptkp # result["pkp"] = pkp # result["pph_setahun"] = pph_setahun result["pph"] = pph result["pph_ta"] = pph_ta return result
def validation_expedition_under_birth(self): if self.birthdate_date > self.polexpedition: raise models.ValidationError('Date of document shipment, prior to birth date')
def _constraint_day(self): if self.day_limit_per_request != -1: if self.number_of_days_temp > self.day_limit_per_request: strWarning = _("Limit per request exceed") raise models.ValidationError(strWarning)
def _check_hierarchy(self): if not self._check_recursion(): raise models.ValidationError( 'Error! A code cannot be a child of itself.')
def _check_range(self): if self.date_end <= self.date_start: strWarning = _("The start date must precede it's end date") raise models.ValidationError(strWarning)
def _check_open_with_action_comments(self): for nc in self: if nc.state == 'open' and not nc.action_comments: raise models.ValidationError( _("Action plan comments are required " "in order to put a nonconformity In Progress."))
def _check_release_date(self): for r in self: if r.date_release > fields.Date.today(): raise models.ValidationError( 'Release date must be in the past')
def _check_br_required(self): for t in self: if t.br_required and not t.business_requirement_id.id: raise models.ValidationError( 'The Business Requirement is mandatory' ' for this type of project category')