Skip to content

Commit

Permalink
Merge pull request #219 from VoicuStefan2001/15.0
Browse files Browse the repository at this point in the history
[15.0][UPD] l10n_ro_partner_create_by_vat
  • Loading branch information
VoicuStefan2001 authored Nov 25, 2024
2 parents 762a0f1 + 2140186 commit c9fd974
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 67 deletions.
9 changes: 6 additions & 3 deletions l10n_ro_edi_ubl_sale_store/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ Deltatech Sale from Store UBL
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:82dad9fd93fb19748471db3f4ba19840a80f821af9ff77805380aea4e6d1276b
!! source digest: sha256:178bfdae61ca5c39660a1eb2d7651134b595cd6aeb8a1ba9c948aa5480f96e79
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github
:target: https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_sale_store
:alt: dhongu/l10n-romania

|badge1| |badge2|
|badge1| |badge2| |badge3|

Features:
- seteaza tipul de efactura ca fiind 751
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_edi_ubl_sale_store/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"deltatech_sale_store",
"l10n_ro_account_edi_ubl",
],
"license": "OPL-1",
"license": "AGPL-3",
"price": 25.00,
"currency": "EUR",
"data": [],
Expand Down
4 changes: 2 additions & 2 deletions l10n_ro_edi_ubl_sale_store/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ <h1 class="title">Deltatech Sale from Store UBL</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:82dad9fd93fb19748471db3f4ba19840a80f821af9ff77805380aea4e6d1276b
!! source digest: sha256:178bfdae61ca5c39660a1eb2d7651134b595cd6aeb8a1ba9c948aa5480f96e79
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_sale_store"><img alt="dhongu/l10n-romania" src="https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_edi_ubl_sale_store"><img alt="dhongu/l10n-romania" src="https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github" /></a></p>
<dl class="docutils">
<dt>Features:</dt>
<dd><ul class="first last simple">
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_partner_create_by_vat_button/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Romania - Partner Create by VAT Button
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:921a3276d297d5675bfb54ca95b8118a4f3de208aa9c18ddc39467cb19a3935b
!! source digest: sha256:1337e7cef78b777afc2f83db67c6b7dd66220f8a1bcbd55c108b302a1244b2f3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_partner_create_by_vat_button/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Romania - Partner Create by VAT Button",
"license": "AGPL-3",
"version": "15.0.1.0.7",
"version": "15.0.1.1.0",
"author": "Dorin Hongu," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Localization",
Expand Down
67 changes: 43 additions & 24 deletions l10n_ro_partner_create_by_vat_button/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from zeep import Client

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

_logger = logging.getLogger(__name__)
Expand All @@ -16,43 +16,62 @@
class ResPartner(models.Model):
_inherit = "res.partner"

warning_companies = fields.Text(string="Warning", store=True, compute="_compute_warning_companies")

@api.depends("vat", "country_id", "street", "city", "state_id")
def _compute_warning_companies(self):
for partner in self:
partner.warning_companies = "Missing:"
if partner.is_company and partner.country_id and partner.country_id.code == "RO":
if not partner.vat:
partner.warning_companies += " VAT,"
if not partner.street:
partner.warning_companies += " Street,"
if not partner.city:
partner.warning_companies += " City,"
if not partner.state_id:
partner.warning_companies += " State,"
if partner.warning_companies.endswith(","):
partner.warning_companies = partner.warning_companies[:-1] + "!"

@api.constrains("vat", "country_id")
def check_vat(self):
if self.env.context.get("no_vat_validation"):
return
partners = self.filtered(lambda p: p.country_id.code != "RO")
return super(ResPartner, partners).check_vat()

@api.model
def create(self, vals):
if "name" in vals and vals["name"]:
vat_number = vals["name"].lower().strip()
if "ro" in vat_number:
vat_number = vat_number.replace("ro", "")
if vat_number.isdigit():
try:
vals["vat"] = vals["name"]
result = self._get_Anaf(vat_number)
if result:
res = self._Anaf_to_Odoo(result)
vals.update(res)
except Exception as e:
_logger.info("ANAF Webservice not working. Exception: % s" % e)

if vals.get("state_id") and not isinstance(vals["state_id"], int):
vals["state_id"] = vals["state_id"].id

partner = super().create(vals)
return partner
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "name" in vals and vals["name"]:
vat_number = vals["name"].lower().strip()
if "ro" in vat_number:
vat_number = vat_number.replace("ro", "")
if vat_number.isdigit():
try:
vals["vat"] = vals["name"]
result = self._get_Anaf(vat_number)
if result:
res = self._Anaf_to_Odoo(result)
vals.update(res)
except Exception as e:
_logger.info("ANAF Webservice not working. Exception: % s" % e)

if vals.get("state_id") and not isinstance(vals["state_id"], int):
vals["state_id"] = vals["state_id"].id

res = super().create(vals_list)
return res

def get_partner_data(self):
if self.country_id and self.country_id.code != "RO":
return False
if self.name and not self.vat:
self.vat = self.name
self.with_context(skip_ro_vat_change=False).ro_vat_change()
res = self.with_context(skip_ro_vat_change=False).ro_vat_change()

return True
return res
# self.onchange_vat_subjected() # fortare compltare ro

def get_partner_name_from_vies(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Romania - Partner Create by VAT Button</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:921a3276d297d5675bfb54ca95b8118a4f3de208aa9c18ddc39467cb19a3935b
!! source digest: sha256:1337e7cef78b777afc2f83db67c6b7dd66220f8a1bcbd55c108b302a1244b2f3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_partner_create_by_vat_button"><img alt="dhongu/l10n-romania" src="https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github" /></a></p>
<blockquote>
Expand Down
13 changes: 13 additions & 0 deletions l10n_ro_partner_create_by_vat_button/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//div[@class='alert alert-warning oe_edit_only']" position="after">
<field name="warning_companies" invisible="1" />
<div
class="alert alert-danger"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('warning_companies','=', 'Missing:')]}"
>
<span>
<field name="warning_companies" />
</span>
</div>
</xpath>
<xpath expr="//sheet" position="before">
<header>
<button
Expand Down
39 changes: 27 additions & 12 deletions l10n_ro_partner_create_by_vat_button/wizard/get_data_form_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@
<field name="model">get.partner.data</field>
<field name="arch" type="xml">
<form string="Get Partner Data">
<div>
<p>Select service for partner:
<field name="partner_id" readonly="True" />
</p>
<field name="state" invisible="1" />
<div states="get">
<div>
<p>Select service for partner:
<field name="partner_id" readonly="True" />
</p>

<field name="service" widget="radio" />
<field name="service" widget="radio" />
</div>
</div>
<div states="set">
<field name="status_message" readonly="True" />
</div>
<footer>
<button
name="do_get_data"
colspan="2"
string="Get Data"
context="{'active_id': active_id}"
type="object"
/>
<div states="get">
<button
name="do_get_data"
string="Get Data"
type="object"
context="{'active_id': active_id}"
class="oe_highlight"
/>
or
<button string="Close" class="oe_link" special="cancel" />
</div>
<div states="set">
<button name="do_back" string="Back" type="object" />
or
<button string="Close" class="oe_link" special="cancel" />
</div>
</footer>
</form>
</field>
Expand Down
38 changes: 35 additions & 3 deletions l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class GetPartnerData(models.TransientModel):
Expand All @@ -10,6 +11,8 @@ class GetPartnerData(models.TransientModel):
default="anaf",
string="Service",
)
state = fields.Selection(selection=[("get", "get"), ("set", "set")], default="get")
status_message = fields.Char()

def default_get(self, fields):
res = super().default_get(fields)
Expand All @@ -22,11 +25,40 @@ def default_get(self, fields):

partner_id = fields.Many2one("res.partner", string="Partner")

def do_back(self):
self.write({"state": "get"})
return {
"type": "ir.actions.act_window",
"res_model": self._name,
"view_mode": "form",
"view_type": "form",
"res_id": self.id,
"views": [(False, "form")],
"target": "new",
}

def do_get_data(self):
if self.partner_id.type == "delivery":
raise ValidationError(_("You can't use this function on delivery contacts."))
if self.service == "anaf":
self.partner_id.get_partner_data()
res = self.partner_id.get_partner_data()
if "warning" in res:
self.status_message = _("Attention! ") + res["warning"]["message"]
else:
self.status_message = _("Partner data updated!")
if self.service == "vies":
self.partner_id.get_partner_name_from_vies()
self.status_message = _("Partner data updated!")
if self.partner_id.zip and hasattr(self.partner_id, "onchange_zip"):
self.partner_id.onchange_zip()
return

self.state = "set"
return {
"type": "ir.actions.act_window",
"res_model": self._name,
"view_mode": "form",
"view_type": "form",
"res_id": self.id,
"views": [(False, "form")],
"target": "new",
}
2 changes: 1 addition & 1 deletion l10n_ro_partner_create_by_vat_openapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Partner Create by VAT from OpenAPI
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2ce4d69f2f128a37e7d50034278032963b72d8431fc504e038f9b4b66d23928e
!! source digest: sha256:63d1392fb655a9929838647876d160e29fd00b4bb6ba024ee8855fe8c2ae67f0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion l10n_ro_partner_create_by_vat_openapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Partner Create by VAT from OpenAPI",
"summary": "Romania - Partner Create by VAT from OpenAPI",
"version": "15.0.1.0.2",
"version": "15.0.1.0.3",
"author": "Terrabit, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Localization",
Expand Down
4 changes: 2 additions & 2 deletions l10n_ro_partner_create_by_vat_openapi/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def button_get_partner_data_openapi(self):
try:
values = self._get_Openapi(vat_number)
except Exception as e:
_logger.warning("OpenAPI interrogation failed:%s", str(e))
values = {}
return "OpenAPI interrogation failed:%s" % str(e)

if values:
if not values["l10n_ro_vat_subjected"]:
Expand All @@ -122,6 +121,7 @@ def button_get_partner_data_openapi(self):
self.active = False
if not self.phone:
self.phone = phone
return

else:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Partner Create by VAT from OpenAPI</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2ce4d69f2f128a37e7d50034278032963b72d8431fc504e038f9b4b66d23928e
!! source digest: sha256:63d1392fb655a9929838647876d160e29fd00b4bb6ba024ee8855fe8c2ae67f0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_partner_create_by_vat_openapi"><img alt="dhongu/l10n-romania" src="https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github" /></a></p>
<p>This modules adds the “Get Partner Data OpenAPI” in the contact from, by adding the vat number
Expand Down
21 changes: 7 additions & 14 deletions l10n_ro_partner_create_by_vat_openapi/wizard/get_partner_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ class GetPartnerData(models.TransientModel):
service = fields.Selection(selection_add=[("openapi", "OpenAPI")])

def do_get_data(self):
super().do_get_data()
res = super().do_get_data()
if self.service == "openapi":
openapi_key = self.env["ir.config_parameter"].sudo().get_param(key="openapi_key", default=False)
if not openapi_key:
raise UserError(_("API Key is missing - please contact support service!"))
self.partner_id.button_get_partner_data_openapi()

action = {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": "Title",
"message": "message",
"sticky": True,
"next": {"type": "ir.actions.act_window_close"},
},
}
return action
result = self.partner_id.button_get_partner_data_openapi()
if result:
self.status_message = result
else:
self.status_message = _("Partner data updated!")
return res

0 comments on commit c9fd974

Please sign in to comment.