def _onchange_linha_digitavel(self): linha = re.sub('[^0-9]', '', self.linha_digitavel or '') if len(linha) in (47, 48): self.linha_digitavel = pretty_format_line(linha) vals = self._get_digitable_line_vals(linha) self.amount = vals.get('valor', 0.0) self.date_maturity = vals.get('vencimento')
def get_barcode_information(self): if self.payment_type in ['03', '04']: linha = re.sub('[^0-9]', '', self.linha_digitavel or '') vals = self._get_digitable_line_vals(linha) linha_digitavel = pretty_format_line(linha) barcode = vals['barcode'] return linha_digitavel, barcode return False, False
def _onchange_linha_digitavel(self): linha = re.sub('[^0-9]', '', self.linha_digitavel or '') if len(linha) in (47, 48): self.linha_digitavel = pretty_format_line(linha) vals = self._get_digitable_line_vals(linha) if self.line_ids: self.line_ids[0].price_unit = vals.get('valor', 0.0) else: self.line_ids = [(0, 0, { 'quantity': 1.0, 'price_unit': vals.get('valor', 0.0) })] if vals.get('vencimento'): self.date_due = vals.get('vencimento')
def action_update_info(self): linha = re.sub('[^0-9]', '', self.linha_digitavel or '') if len(linha) not in (47, 48): raise UserError( 'Tamanho da linha digitável inválido %s' % len(linha)) vals = self._get_digitable_line_vals(linha) linha_digitavel = pretty_format_line(linha) barcode = vals['barcode'] order_line = self.env['payment.order.line'].search( [('move_line_id', '=', self.move_line_id.id)]) invoice = self.move_line_id.invoice_id if order_line and order_line.state == 'draft': order_line.write({ 'payment_mode_id': self.payment_mode_id.id, 'linha_digitavel': linha_digitavel, 'bank_account_id': self.bank_account_id.id, 'date_maturity': self.date_maturity or order_line.date_maturity }) self.move_line_id.write({ 'payment_mode_id': self.payment_mode_id.id, 'date_maturity': self.date_maturity or self.move_line_id.date_maturity, }) elif order_line: raise UserError( 'O pagamento já foi processado! \ Não é possível modificar informações aqui!') else: vals = invoice.prepare_payment_line_vals(self.move_line_id) vals['date_maturity'] = \ self.date_maturity or self.move_line_id.date_maturity vals['linha_digitavel'] = linha_digitavel vals['barcode'] = barcode vals['bank_account_id'] = self.bank_account_id.id self.env['payment.order.line'].action_generate_payment_order_line( self.payment_mode_id, vals) if self.date_maturity: self.move_line_id.write({ 'payment_mode_id': self.payment_mode_id.id, 'date_maturity': self.date_maturity, })
def test_pretty_format_48(self): dig_line = '858700000049800001791819107622050820415823300017' dig_line = pretty_format_line(dig_line) self.assertEqual( dig_line, '858700000049 800001791819 107622050820 415823300017')
def test_pretty_format_47(self): dig_line = '75691306980124564000600371460015177050000035280' dig_line = pretty_format_line(dig_line) self.assertEqual( dig_line, '75691.30698 01245.640006 00371.460015 1 77050000035280')