Skip to content

Commit

Permalink
[IMP] l10n_it_website_portal_fatturapa: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed Jan 28, 2022
1 parent 9f54532 commit bb85524
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 83 deletions.
8 changes: 3 additions & 5 deletions l10n_it_website_portal_fatturapa/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
"version": "12.0.1.3.0",
"author": "Odoo Community Association (OCA)",
"category": "Localization/Italy",
"website": "https://github.com/OCA/l10n-italy/tree/"
"12.0/l10n_it_website_portal_fatturapa",
"website": "https://github.com/OCA/l10n-italy"
"12.0/l10n_it_website_portal_fatturapa",
"license": "AGPL-3",
"depends": [
"l10n_it_fatturapa",
"l10n_it_website_portal_fiscalcode",
"l10n_it_website_portal_ipa",
],
"data": [
"views/l10n_it_website_portal_fatturapa_templates.xml"
],
"data": ["views/l10n_it_website_portal_fatturapa_templates.xml"],
"auto_install": True,
}
83 changes: 50 additions & 33 deletions l10n_it_website_portal_fatturapa/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,55 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.http import request
from odoo.addons.l10n_it_website_portal_fiscalcode.controllers.main import \
WebsitePortalFiscalCode
from odoo.tools.translate import _

FATTURAPA_PORTAL_FIELDS = \
['codice_destinatario', 'firstname', 'lastname',
'pec_destinatario', 'country_id', 'fiscalcode', 'zipcode', 'vat',
'electronic_invoice_subjected', 'street', 'city',
'is_pa', 'ipa_code', 'eori_code', 'electronic_invoice_obliged_subject']
from odoo.addons.l10n_it_website_portal_fiscalcode.controllers.main import (
WebsitePortalFiscalCode,
)

FATTURAPA_PORTAL_FIELDS = [
"codice_destinatario",
"firstname",
"lastname",
"pec_destinatario",
"country_id",
"fiscalcode",
"zipcode",
"vat",
"electronic_invoice_subjected",
"street",
"city",
"is_pa",
"ipa_code",
"eori_code",
"electronic_invoice_obliged_subject",
]
WebsitePortalFiscalCode.OPTIONAL_BILLING_FIELDS.extend(FATTURAPA_PORTAL_FIELDS)


class WebsitePortalFatturapa(WebsitePortalFiscalCode):

def details_form_validate(self, data):
# when checkbox electronic_invoice_subjected is not checked,
# it is not posted
data['electronic_invoice_subjected'] = data.get(
'electronic_invoice_subjected', False)
data["electronic_invoice_subjected"] = data.get(
"electronic_invoice_subjected", False
)
if data["electronic_invoice_subjected"]:
data["electronic_invoice_obliged_subject"] = True
error, error_message = \
super(WebsitePortalFatturapa, self).details_form_validate(data)
error, error_message = super(
WebsitePortalFatturapa, self
).details_form_validate(data)
partner_sudo = request.env.user.partner_id.sudo()
error, error_message = \
self.validate_partner_firstname(data, error, error_message)
error, error_message = self.validate_partner_firstname(
data, error, error_message
)

partner_values = self.get_portal_fatturapa_partner_values(
data, partner_sudo)
dummy_partner = request.env['res.partner'].new(partner_values)
partner_values = self.get_portal_fatturapa_partner_values(data, partner_sudo)
dummy_partner = request.env["res.partner"].new(partner_values)
try:
dummy_partner._check_ftpa_partner_data()
except ValidationError as ve:
error['error'] = 'error'
error["error"] = "error"
error_message.append(ve.name)
return error, error_message

Expand All @@ -46,28 +61,30 @@ def get_portal_fatturapa_partner_values(self, data, partner_sudo):
partner_values = partner_sudo.read(constr_fields)[0]

# Update them with fields that might be edited by the user
new_partner_values = {f_name: data.get(f_name)
for f_name in FATTURAPA_PORTAL_FIELDS}
if new_partner_values.get('country_id'):
new_partner_values['country_id'] = \
int(new_partner_values['country_id'])
new_partner_values.update({
'zip': new_partner_values.pop('zipcode', '')})
new_partner_values = {
f_name: data.get(f_name) for f_name in FATTURAPA_PORTAL_FIELDS
}
if new_partner_values.get("country_id"):
new_partner_values["country_id"] = int(new_partner_values["country_id"])
new_partner_values.update({"zip": new_partner_values.pop("zipcode", "")})
partner_values.update(new_partner_values)
return partner_values

def validate_partner_firstname(self, data, error, error_message):
# Compute name field, using First name and Last name
if all(f in data for f in ['name', 'firstname', 'lastname']):
lastname = data.get('lastname')
firstname = data.get('firstname')
if all(f in data for f in ["name", "firstname", "lastname"]):
lastname = data.get("lastname")
firstname = data.get("firstname")
if lastname or firstname:
data.update(
name=request.env['res.partner']._get_computed_name(
lastname, firstname))
name=request.env["res.partner"]._get_computed_name(
lastname, firstname
)
)
else:
error['firstname'] = 'error'
error['lastname'] = 'error'
error["firstname"] = "error"
error["lastname"] = "error"
error_message.append(
_('At least one of first name and last name is required'))
_("At least one of first name and last name is required")
)
return error, error_message
2 changes: 1 addition & 1 deletion l10n_it_website_portal_fatturapa/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fields `is_pa` and `ipa_code` are not shown in the frontend because Odoo core always supposes that frontend users are individual, and these fields are only meaningful for companies.
Fields `is_pa` and `ipa_code` are not shown in the frontend because Odoo core always supposes that frontend users are individual, and these fields are only meaningful for companies.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
odoo.define('l10n_it_website_portal_fatturapa', function(require) {
'use strict';
require('web.core');
odoo.define("l10n_it_website_portal_fatturapa", function (require) {
"use strict";
require("web.core");

$(document).ready(function () {
var details_div_selector = ".o_portal_details";
var $details_div = $(details_div_selector);
if (!$details_div.length) {
return $.Deferred().reject(
"DOM doesn't contain " + details_div_selector);
return $.Deferred().reject("DOM doesn't contain " + details_div_selector);
}
var $electronic_invoice_subjected_input = $details_div
.find("input[name='electronic_invoice_subjected'][type='checkbox']");
var $div_electronic_invoice_subjected_fields = $details_div
.find(".div_electronic_invoice_subjected_fields");
var $electronic_invoice_subjected_input = $details_div.find(
"input[name='electronic_invoice_subjected'][type='checkbox']"
);
var $div_electronic_invoice_subjected_fields = $details_div.find(
".div_electronic_invoice_subjected_fields"
);

var compute_e_inv_fields_visibility = function(){
var compute_e_inv_fields_visibility = function () {
if ($electronic_invoice_subjected_input[0].checked) {
$div_electronic_invoice_subjected_fields.show();
} else {
Expand All @@ -24,17 +25,18 @@ odoo.define('l10n_it_website_portal_fatturapa', function(require) {
compute_e_inv_fields_visibility();
$electronic_invoice_subjected_input.change(compute_e_inv_fields_visibility);

var $is_pa = $details_div
.find("input[name='is_pa'][type='checkbox']");
var $is_pa = $details_div.find("input[name='is_pa'][type='checkbox']");
if (!$is_pa.length) {
return;
}
var $codice_destinatario_div = $details_div
.find("input[name='codice_destinatario'][type='text']").parent();
.find("input[name='codice_destinatario'][type='text']")
.parent();
var $pec_destinatario_div = $details_div
.find("input[name='pec_destinatario'][type='text']").parent();
.find("input[name='pec_destinatario'][type='text']")
.parent();

var compute_destinatario_fields_visibility = function(){
var compute_destinatario_fields_visibility = function () {
if (!$is_pa[0].checked) {
$codice_destinatario_div.show();
$pec_destinatario_div.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,120 @@
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<template id="assets_frontend" inherit_id="web.assets_frontend" name="Website Portal Electronic Invoice">
<template
id="assets_frontend"
inherit_id="web.assets_frontend"
name="Website Portal Electronic Invoice"
>
<xpath expr="//script[last()]" position="after">
<script type="text/javascript"
src="/l10n_it_website_portal_fatturapa/static/src/js/l10n_it_website_portal_fatturapa.js"/>
<script
type="text/javascript"
src="/l10n_it_website_portal_fatturapa/static/src/js/l10n_it_website_portal_fatturapa.js"
/>
</xpath>
</template>

<template id="fatturapa_details" name="Add fatturapa fields" inherit_id="l10n_it_website_portal_fiscalcode.fiscalcode_details">
<template
id="fatturapa_details"
name="Add fatturapa fields"
inherit_id="l10n_it_website_portal_fiscalcode.fiscalcode_details"
>
<xpath expr="//input[@name='name']/.." position="attributes">
<attribute name="t-attf-class" separator=" " add="#{'o_hidden' if not partner.is_company else ''}"/>
<attribute
name="t-attf-class"
separator=" "
add="#{'o_hidden' if not partner.is_company else ''}"
/>
</xpath>
<xpath expr="//input[@name='name']/.." position="after">
<t t-if="not partner.is_company">
<div class="clearfix"/>
<div t-attf-class="form-group #{error.get('firstname') and 'has-error' or ''} col-lg-6">
<div class="clearfix" />
<div
t-attf-class="form-group #{error.get('firstname') and 'has-error' or ''} col-lg-6"
>
<label class="control-label" for="firstname">
Your First Name
</label>
<input type="text" name="firstname" class="form-control"
t-att-value="firstname or partner.firstname"/>
<input
type="text"
name="firstname"
class="form-control"
t-att-value="firstname or partner.firstname"
/>
</div>
<div t-attf-class="form-group #{error.get('lastname') and 'has-error' or ''} col-lg-6">
<div
t-attf-class="form-group #{error.get('lastname') and 'has-error' or ''} col-lg-6"
>
<label class="control-label" for="lastname">
Your Last Name
</label>
<input type="text" name="lastname" class="form-control"
t-att-value="lastname or partner.lastname"/>
<input
type="text"
name="lastname"
class="form-control"
t-att-value="lastname or partner.lastname"
/>
</div>
<div class="clearfix"/>
<div class="clearfix" />
</t>
</xpath>
<xpath expr="//div[hasclass('o_portal_details')]/div[1]/div[1]" position="after">
<xpath
expr="//div[hasclass('o_portal_details')]/div[1]/div[1]"
position="after"
>
<!-- after state_id -->
<div class="row">
<div class="col-xl-6 form-group div_electronic_invoice_subjected">
<input type="checkbox" name="electronic_invoice_subjected"
style="width: auto; margin:0px"
t-att-checked="electronic_invoice_subjected or partner.electronic_invoice_subjected"/>
<input
type="checkbox"
name="electronic_invoice_subjected"
style="width: auto; margin:0px"
t-att-checked="electronic_invoice_subjected or partner.electronic_invoice_subjected"
/>
<label for="electronic_invoice_subjected" style="margin-left:5px">
Enable receiving electronic invoice
</label>
</div>
</div>
<div class="row div_electronic_invoice_subjected_fields">
<div t-attf-class="form-group #{error.get('codice_destinatario') and 'o_has_error' or ''} col-xl-6">
<div
t-attf-class="form-group #{error.get('codice_destinatario') and 'o_has_error' or ''} col-xl-6"
>
<label class="col-form-label" for="codice_destinatario">
Addressee code
</label>
<input type="text" name="codice_destinatario"
t-attf-class="form-control #{error.get('codice_destinatario') and 'is-invalid' or ''}"
t-att-value="codice_destinatario or partner.codice_destinatario"/>
<input
type="text"
name="codice_destinatario"
t-attf-class="form-control #{error.get('codice_destinatario') and 'is-invalid' or ''}"
t-att-value="codice_destinatario or partner.codice_destinatario"
/>
</div>
<div t-attf-class="form-group #{error.get('pec_destinatario') and 'o_has_error' or ''} col-xl-6">
<div
t-attf-class="form-group #{error.get('pec_destinatario') and 'o_has_error' or ''} col-xl-6"
>
<label class="col-form-label" for="pec_destinatario">
Or PEC address for Electronic invoicing
</label>
<input type="text" name="pec_destinatario"
t-attf-class="form-control #{error.get('pec_destinatario') and 'is-invalid' or ''}"
t-att-value="pec_destinatario or partner.pec_destinatario"/>
<input
type="text"
name="pec_destinatario"
t-attf-class="form-control #{error.get('pec_destinatario') and 'is-invalid' or ''}"
t-att-value="pec_destinatario or partner.pec_destinatario"
/>
</div>
<div t-attf-class="form-group #{error.get('eori_code') and 'o_has_error' or ''} col-xl-6">
<div
t-attf-class="form-group #{error.get('eori_code') and 'o_has_error' or ''} col-xl-6"
>
<label class="col-form-label label-optional" for="eori_code">
EORI code
</label>
<input type="text" name="eori_code"
t-attf-class="form-control #{error.get('eori_code') and 'is-invalid' or ''}"
t-att-value="eori_code or partner.eori_code"/>
<input
type="text"
name="eori_code"
t-attf-class="form-control #{error.get('eori_code') and 'is-invalid' or ''}"
t-att-value="eori_code or partner.eori_code"
/>
</div>
</div>
</xpath>
Expand Down
6 changes: 6 additions & 0 deletions setup/l10n_it_website_portal_fatturapa/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit bb85524

Please sign in to comment.