-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodels.py
44 lines (40 loc) · 1.55 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api
from odoo.exceptions import UserError,ValidationError
from datetime import datetime
from bs4 import BeautifulSoup
import requests
class ResCurrency(models.Model):
_inherit = 'res.currency'
@api.model
def update_dolarbna(self):
dolarbna_url = self.env['ir.config_parameter'].get_param('dolar_bna','https://www.bna.com.ar/Personas')
if not dolarbna_url:
raise UserError('No esta presente URL de BNA')
page = requests.get(dolarbna_url)
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(id="billetes")
tds = results.find_all("td",class_=False)
if len(tds) < 2:
raise ValidationError('No se puede determinar el dolar BNA #1')
#try:
value = tds[1].text
value = value.replace('<td>','')
value = value.replace('</td>','')
value = float(value.replace(',','.'))
#except:
# raise ValidationError('No se puede determinar el valor BNA #2')
currency_id = self.search([('name','=','USD')])
if currency_id:
vals = {
'name': str(datetime.now())[:10],
'currency_id': currency_id.id,
'rate': 1 / value
}
rate = self.env['res.currency.rate'].search([('currency_id','=',currency_id.id),('name','=',str(datetime.now())[:10])])
if not rate:
return_id = self.env['res.currency.rate'].create(vals)