Skip to content
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: 2 additions & 0 deletions addons/l10n_pe_website_sale/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Be able to see Identification Type in ecommerce checkout form.
==============================================================
3 changes: 3 additions & 0 deletions addons/l10n_pe_website_sale/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
27 changes: 27 additions & 0 deletions addons/l10n_pe_website_sale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
"name": "Peruvian eCommerce",
"version": "0.1",
"summary": "Be able to see Identification Type in ecommerce checkout form.",
"category": "Accounting/Localizations/Website",
"author": "Vauxoo, Odoo",
"license": "LGPL-3",
"depends": [
"website_sale",
"l10n_pe",
],
"data": [
"data/ir_model_fields.xml",
"views/templates.xml",
],
"demo": [
"demo/website_demo.xml",
],
"assets": {
"web.assets_frontend": [
"l10n_pe_website_sale/static/src/js/website_sale.js",
],
},
"installable": True,
"auto_install": True,
}
2 changes: 2 additions & 0 deletions addons/l10n_pe_website_sale/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main
93 changes: 93 additions & 0 deletions addons/l10n_pe_website_sale/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request

from odoo.addons.website_sale.controllers.main import WebsiteSale


class L10nPEWebsiteSale(WebsiteSale):
def _get_mandatory_fields_billing(self, country_id=False):
"""Extend mandatory fields to add new identification, responsibility
city_id and distrcit fields when company is Peru"""
res = super()._get_mandatory_fields_billing(country_id)
if country_id:
country = request.env['res.country'].browse(country_id)
if country and country == request.env.ref("base.pe"):
res += ["city_id", "l10n_pe_district"]
res.remove("city")
if request.website.sudo().company_id.country_id.code == "PE":
res += ["l10n_latam_identification_type_id", "vat"]
return res

def _get_mandatory_fields_shipping(self, country_id=False):
"""Extend mandatory fields to add city_id and district fields when the selected country is Peru"""
res = super()._get_mandatory_fields_shipping(country_id)
if country_id:
country = request.env['res.country'].browse(country_id)
if country and country == request.env.ref("base.pe"):
res += ["city_id", "l10n_pe_district"]
res.remove("city")
return res

def _get_country_related_render_values(self, kw, render_values):
res = super()._get_country_related_render_values(kw, render_values)

if request.website.sudo().company_id.country_id.code == "PE":
values = render_values["checkout"]
state = (
"state_id" in values
and values["state_id"] != ""
and request.env["res.country.state"].browse(int(values["state_id"]))
)
city = (
"city_id" in values
and values["city_id"] != ""
and request.env["res.city"].browse(int(values["city_id"]))
)
to_include = {
"identification": kw.get("l10n_latam_identification_type_id"),
"identification_types": request.env["l10n_latam.identification.type"].sudo().search(
["|", ("country_id", "=", False), ("country_id.code", "=", "PE")]
),
}
if state:
to_include["state"] = state
to_include["state_cities"] = state.get_website_sale_cities()
if city:
to_include["city"] = city
to_include["city_districts"] = city.get_website_sale_districts()
res.update(to_include)
return res

def _get_vat_validation_fields(self, data):
res = super()._get_vat_validation_fields(data)
if request.website.sudo().company_id.country_id.code == "PE":
res.update(
{
"l10n_latam_identification_type_id": int(data["l10n_latam_identification_type_id"])
if data.get("l10n_latam_identification_type_id")
else False
}
)
res.update({"name": data["name"] if data.get("name") else False})
return res

@http.route(
['/shop/state_infos/<model("res.country.state"):state>'],
type="json",
auth="public",
methods=["POST"],
website=True,
)
def state_infos(self, state, **kw):
return dict(
cities=[(c.id, c.name, c.l10n_pe_code) for c in state.get_website_sale_cities()],
)

@http.route(
['/shop/city_infos/<model("res.city"):city>'], type="json", auth="public", methods=["POST"], website=True
)
def city_infos(self, city, **kw):
return dict(
districts=[(d.id, d.name, d.code) for d in city.get_website_sale_districts()],
)
13 changes: 13 additions & 0 deletions addons/l10n_pe_website_sale/data/ir_model_fields.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<function model="ir.model.fields" name="formbuilder_whitelist">
<value>res.partner</value>
<value eval="[
'city_id',
'l10n_latam_identification_type_id',
'l10n_pe_district',
]"/>
</function>

</odoo>
33 changes: 33 additions & 0 deletions addons/l10n_pe_website_sale/demo/website_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="default_website_pe" model="website">
<field name="name">(PE) Peruvian Website</field>
<field name="company_id" ref="l10n_pe.demo_company_pe" />
<field name="logo" type="base64" file="l10n_pe_website_sale/static/description/icon.png" />
<field
name="domain"
model="ir.config_parameter"
eval="obj().env['ir.config_parameter'].sudo().get_param('web.base.url')"
/>
</record>
<function model="payment.provider" name="copy">
<value eval="[ref('payment.payment_provider_transfer')]" />
<value eval="{'company_id': ref('l10n_pe.demo_company_pe'), 'state': 'enabled'}" />
</function>
<function model="product.pricelist" name="write">
<value
model="product.pricelist"
eval="obj().search([('currency_id', '=', ref('base.PEN')), ('company_id', '=', ref('l10n_pe.demo_company_pe'))]).id"
/>
<value model="website" eval="{'sequence': 1, 'website_id': ref('l10n_pe_website_sale.default_website_pe')}" />
</function>
<function model="product.product" name="write">
<value model="product.product" eval="obj().search([('taxes_id', '=', False)]).ids" />
<value
model="account.tax"
eval="{'taxes_id': [(4, obj().search([('type_tax_use', '=', 'sale'), ('tax_group_id', '=', ref('account.%s_tax_group_exo' % ref('l10n_pe.demo_company_pe'))), ('company_id', '=', ref('l10n_pe.demo_company_pe'))]).id)]}"
/>
</function>

</odoo>
76 changes: 76 additions & 0 deletions addons/l10n_pe_website_sale/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_pe_website_sale
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-04-04 22:20+0000\n"
"PO-Revision-Date: 2023-04-04 22:20+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_info
msgid ""
"Changing Identification type is not allowed once document(s) have been "
"issued for your account. Please contact us directly for this operation."
msgstr ""
"No se permite cambiar el tipo de identificación una vez que se hayan emitido los documentos "
"para su cuenta. Póngase en contacto con nosotros directamente para esta operación."

#. module: l10n_pe_website_sale
#: model:ir.model,name:l10n_pe_website_sale.model_res_city
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_address_info
msgid "City"
msgstr "Ciudad"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_address_info
msgid "City..."
msgstr "Ciudad..."

#. module: l10n_pe_website_sale
#: model:ir.model,name:l10n_pe_website_sale.model_res_country_state
msgid "Country state"
msgstr "Estado"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_address_info
msgid "District"
msgstr "Distrito"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_address_info
msgid "District..."
msgstr "Distrito..."

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_info
msgid "Identification Type"
msgstr "Tipo de Identificación"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.partner_info
msgid "Identification Type..."
msgstr "Tipo de Identificación..."

#. module: l10n_pe_website_sale
#: model:website,prevent_zero_price_sale_text:l10n_pe_website_sale.default_website_pe
msgid "Not Available For Sale"
msgstr "No disponible para la venta"

#. module: l10n_pe_website_sale
#: model_terms:ir.ui.view,arch_db:l10n_pe_website_sale.address
msgid "Number"
msgstr "Número"

#. module: l10n_pe_website_sale
#: model:ir.model,name:l10n_pe_website_sale.model_website
msgid "Website"
msgstr "Sitio web"
5 changes: 5 additions & 0 deletions addons/l10n_pe_website_sale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import res_city
from . import res_country_state
from . import website
10 changes: 10 additions & 0 deletions addons/l10n_pe_website_sale/models/res_city.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class City(models.Model):
_inherit = "res.city"

def get_website_sale_districts(self):
return self.env["l10n_pe.res.city.district"].sudo().search([("city_id", "=", self.id)])
10 changes: 10 additions & 0 deletions addons/l10n_pe_website_sale/models/res_country_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class CountryState(models.Model):
_inherit = "res.country.state"

def get_website_sale_cities(self):
return self.env["res.city"].sudo().search([("state_id", "=", self.id)])
12 changes: 12 additions & 0 deletions addons/l10n_pe_website_sale/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class Website(models.Model):
_inherit = "website"

def _display_partner_b2b_fields(self):
"""Peruvian localization must always display b2b fields"""
self.ensure_one()
return self.company_id.country_id.code == "PE" or super()._display_partner_b2b_fields()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading