Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][upd] partner by vat openapi #168

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion l10n_ro_partner_create_by_vat_openapi/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import json
import logging
from datetime import datetime
from urllib.request import Request, urlopen

from stdnum.eu.vat import check_vies

from odoo import _, api, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)
Expand All @@ -19,6 +20,8 @@
class ResPartner(models.Model):
_inherit = "res.partner"

last_updated_at = fields.Date(string="Last Updated")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trebuie si asta?


# @api.model
# def create(self, vals):
# partner = super().create(vals)
Expand All @@ -28,6 +31,10 @@ class ResPartner(models.Model):
# name = name.replace("ro", "")
# return partner

def compute_last_updated_at(self, data):
date = data[:10]
self.last_updated_at = datetime.strptime(date, "%Y-%m-%d").date()

@api.model
def _get_Openapi(self, cod):
result = {}
Expand Down Expand Up @@ -61,6 +68,8 @@ def _get_Openapi(self, cod):
"zip": res["cod_postal"] and res["cod_postal"] or "",
"l10n_ro_vat_subjected": bool(res["tva"]),
"state_id": state,
"radiata": res["radiata"],
"last_update": res["meta"]["updated_at"],
"company_type": "company",
}

Expand Down Expand Up @@ -112,7 +121,13 @@ def button_get_partner_data_openapi(self):
if values:
if not values["l10n_ro_vat_subjected"]:
values["vat"] = self.vat.replace("RO", "")
self.compute_last_updated_at(values["last_update"])
values.pop("last_update")
radiata = values["radiata"]
values.pop("radiata")
self.write(values)
if radiata:
self.active = False

else:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
/>
</header>
</xpath>
<xpath expr="//field[@name='vat']" position="after">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

se incarca formulatul cu informatii inutile

<field name="last_updated_at" attrs="{'invisible':[('last_updated_at','=',False)]}" />
</xpath>
</field>
</record>
</data>
Expand Down
Loading