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

[FW][FIX] l10n_ar_ux: Recompute the commercial partner for edit de contact form in portal #931

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion l10n_ar_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': 'Argentinian Accounting UX',
'version': "17.0.1.3.0",
'version': "17.0.1.4.0",
'category': 'Localization/Argentina',
'sequence': 14,
'author': 'ADHOC SA',
Expand Down
25 changes: 19 additions & 6 deletions l10n_ar_ux/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,28 @@ def details_form_validate(self, data):
error_message.extend(write_message)
return error, error_message

def values_preprocess_ar(self, values):
""" We preprocess the ar-post data to ensure the correct assignment of many2one fields."""
new_values = dict()
partner_fields = request.env['res.partner']._fields
ar_camp = ['l10n_ar_afip_responsibility_type_id', 'l10n_latam_identification_type_id', 'commercial_partner_id']

for k, v in values.items():
# Convert the values for many2one fields to integer since they are used as IDs
if k in partner_fields and k in ar_camp and partner_fields[k].type == 'many2one':
new_values[k] = bool(v) and int(v) or False

return new_values

@route()
def account(self, redirect=None, **post):
partner = request.env.user.partner_id
if post and request.httprequest.method == 'POST':
if not partner.can_edit_vat():
post['country_id'] = str(partner.country_id.id)
error, _error_message = self.details_form_validate(post)
if not error:
post.pop('commercial_partner_id', False)
post.pop('vat', False)
post.pop('l10n_latam_identification_type_id', False)
post.pop('l10n_ar_afip_responsibility_type_id', False)
#Procesamos los datos del post para asignar correctamente los valores de los campos many2one
post.update(self.values_preprocess_ar(post))

response = super().account(redirect=redirect, **post)
identification_types = request.env['l10n_latam.identification.type'].sudo().search([])
Expand All @@ -52,7 +62,10 @@ def account(self, redirect=None, **post):
partner = request.env['res.users'].browse(uid).partner_id if uid else request.env['res.partner']
partner = partner.with_context(show_address=1).sudo()
response.qcontext.update({
'afip_respo_type': post.get('l10n_ar_afip_responsibility_type_id') or partner.l10n_ar_afip_responsibility_type_id.id,
'latam_ident_type': post.get('l10n_latam_identification_type_id') or partner.l10n_latam_identification_type_id.id,
'identification_types': identification_types,
'afip_responsibilities': afip_responsibilities,
'partner': partner})
'partner': partner,
'partner_can_edit_vat': partner.can_edit_vat()})
return response
10 changes: 5 additions & 5 deletions l10n_ar_ux/views/portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<label class="control-label" for="l10n_latam_identification_type_id">Document Type</label>
<input name="commercial_partner_id" class="form-control" t-att-value="partner.commercial_partner_id.id" type='hidden'/>
<t t-set="document_type" t-value="partner.commercial_partner_id.l10n_latam_identification_type_id"/>
<t t-if="document_type">
<t t-if="not partner_can_edit_vat">
<p class="form-control" t-out="document_type.name" readonly="1" title="Changing your document type is not allowed. Please contact us directly for this operation."/>
<input name="l10n_latam_identification_type_id" class="form-control" t-att-value="document_type.id" type='hidden'/>
</t>
<t t-else="">
<select name="l10n_latam_identification_type_id" class="form-control">
<option value="">Document Type...</option>
<t t-foreach="identification_types or []" t-as="document_identification">
<option t-att-value="document_identification.id" t-att-selected="str(document_identification.id) == l10n_latam_identification_type_id">
<option t-att-value="document_identification.id" t-att-selected="document_identification.id == latam_ident_type">
<t t-out="document_identification.name"/>
</option>
</t>
Expand All @@ -38,22 +38,22 @@
<!-- Add document number -->
<div t-attf-class="form-group #{error.get('vat') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="vat">Document Number</label>
<input type="text" name="vat" t-attf-class="form-control #{error.get('vat') and 'is-invalid' or ''}" t-att-value="partner.commercial_partner_id.vat or vat" t-att-readonly="'1' if partner.commercial_partner_id.vat else None" t-att-title="'Changing your document number is not allowed. Please contact us directly for this operation.' if partner.commercial_partner_id.vat else None"/>
<input type="text" name="vat" t-attf-class="form-control #{error.get('vat') and 'is-invalid' or ''}" t-att-value="partner.commercial_partner_id.vat or vat" t-att-readonly="'1' if not partner_can_edit_vat else None" t-att-title="'Changing your document number is not allowed. Please contact us directly for this operation.' if partner.commercial_partner_id.vat else None"/>
</div>

<!-- Add AFIP Responsibility -->
<div t-attf-class="form-group #{error.get('l10n_ar_afip_responsibility_type_id') and 'has-error' or ''} col-xl-6">
<label class="control-label" for="l10n_ar_afip_responsibility_type_id">AFIP Responsibility</label>
<t t-set="afip_responsibility" t-value="partner.commercial_partner_id.l10n_ar_afip_responsibility_type_id"/>
<t t-if="afip_responsibility">
<t t-if="not partner_can_edit_vat">
<p class="form-control" t-out="afip_responsibility.name" readonly="1" title="Changing your document type is not allowed. Please contact us directly for this operation."/>
<input name="l10n_ar_afip_responsibility_type_id" class="form-control" t-att-value="afip_responsibility.id" type='hidden'/>
</t>
<t t-else="">
<select name="l10n_ar_afip_responsibility_type_id" class="form-control">
<option value="">AFIP Responsibility...</option>
<t t-foreach="afip_responsibilities or []" t-as="afip_res">
<option t-att-value="afip_res.id" t-att-selected="str(afip_res.id) == l10n_ar_afip_responsibility_type_id">
<option t-att-value="afip_res.id" t-att-selected="afip_res.id == afip_respo_type">
<t t-out="afip_res.name"/>
</option>
</t>
Expand Down