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][MIG+IMP] website_account_fiscal_position_partner_type #830

Merged
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
6 changes: 6 additions & 0 deletions setup/website_account_fiscal_position_partner_type/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,
)
87 changes: 87 additions & 0 deletions website_account_fiscal_position_partner_type/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
============================================
Website Account Fiscal Position Partner Type
============================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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-OCA%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/13.0/website_account_fiscal_position_partner_type
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-13-0/e-commerce-13-0-website_account_fiscal_position_partner_type
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/113/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows e-commerce customers to select if they're end customers or companies.

This module has been designed to be used according the EU One-Stop-Shop in combination with l10n_eu_oss for helping to differentiate which taxes have to be applied.

**Table of contents**

.. contents::
:local:

Usage
=====

After allowing e-commerce customers to a free sign up:

#. Once the customer wants to buy a product in the e-commerce, he/she will have to specify the partner type field (End customer/company) before finishing the checkout.

#. Depending on the partner type, the applied taxes to the products may change.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_account_fiscal_position_partner_type%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Sygel Technology

Contributors
~~~~~~~~~~~~

* `Sygel <https://www.sygel.es>`_:

* Harald Panten
* Valentin Vinagre

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/13.0/website_account_fiscal_position_partner_type>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions website_account_fiscal_position_partner_type/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Valentin Vinagre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import controllers
from . import models
20 changes: 20 additions & 0 deletions website_account_fiscal_position_partner_type/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 Valentín Vinagre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Website Account Fiscal Position Partner Type",
"version": "15.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Sygel Technology," "Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"development_status": "Beta",
"depends": ["account_fiscal_position_partner_type", "website_sale"],
"data": [
"views/website_sale.xml",
"views/portal_templates.xml",
"views/auth_signup_login_templates.xml",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Valentin Vinagre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import main
from . import portal
109 changes: 109 additions & 0 deletions website_account_fiscal_position_partner_type/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2021 Valentin Vinagre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, http
from odoo.http import request

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


class WebsiteSale(WebsiteSale):
def values_postprocess(self, order, mode, values, errors, error_msg):
new_values, errors, error_msg = super(WebsiteSale, self).values_postprocess(
order=order, mode=mode, values=values, errors=errors, error_msg=error_msg
)
if mode[1] in ("billing") and values.get("fiscal_position_type", False):
new_values.update(
{"fiscal_position_type": values.get("fiscal_position_type")}
)
return new_values, errors, error_msg

def checkout_form_validate(self, mode, all_form_values, data):
old_context = request.context
request.context = dict(
request.context,
fiscal_position_type=all_form_values.get("fiscal_position_type"),
)
error, error_message = super().checkout_form_validate(
mode, all_form_values, data
)
request.context = old_context
if data.get("fiscal_position_type"):
partner_su = (
request.env["res.partner"]
.sudo()
.browse(int(data["partner_id"]))
.exists()
)
fiscal_position_type_change = (
partner_su
and "fiscal_position_type" in data
and data["fiscal_position_type"] != partner_su.fiscal_position_type
)
if fiscal_position_type_change and not partner_su.can_edit_vat():
error["fiscal_position_type"] = "error"
error_message.append(

Check warning on line 46 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L45-L46

Added lines #L45 - L46 were not covered by tests
_(
"Changing partner type is not allowed once invoices have "
"been issued for your account. Please contact us directly"
" for this operation."
)
)
return error, error_message

@http.route()
def address(self, **kw):
res = super(WebsiteSale, self).address(**kw)
if res.qcontext:
mode = res.qcontext.get("mode", False)
if mode and mode[1] == "billing":
# Get default position
def_fiscpostype = (
request.website.company_id.default_fiscal_position_type or "b2c"
)
# Get position if exist order
order = request.website.sale_get_order()
if order.partner_id:
def_fiscpostype = order.partner_id.fiscal_position_type
# if posted, get the last value
if kw.get("submitted", False):
if res.qcontext.get("error", False):
def_fiscpostype = kw.get(
"fiscal_position_type", def_fiscpostype
)
# get all options
afp_obj = request.env["account.fiscal.position"].sudo()
res.qcontext.update(
{
"def_fiscpostype": def_fiscpostype,
"fiscpostypevalues": dict(
afp_obj._fields["fiscal_position_type"].selection
),
}
)
return res


class AuthSignupHome(AuthSignupHome):
def get_auth_signup_qcontext(self):
qcontext = super().get_auth_signup_qcontext()

Check warning on line 90 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L90

Added line #L90 was not covered by tests
qcontext.update(
{k: v for (k, v) in request.params.items() if k in {"fiscal_position_type"}}
)
afp_obj = request.env["account.fiscal.position"].sudo()
qcontext["fiscpostypevalues"] = dict(

Check warning on line 95 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L94-L95

Added lines #L94 - L95 were not covered by tests
afp_obj._fields["fiscal_position_type"].selection
)
if not qcontext.get("fiscal_position_type_selected"):
def_fiscpostype = (

Check warning on line 99 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L99

Added line #L99 was not covered by tests
request.website.company_id.default_fiscal_position_type or "b2c"
)
qcontext["fiscal_position_type_selected"] = def_fiscpostype
return qcontext

Check warning on line 103 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L102-L103

Added lines #L102 - L103 were not covered by tests

def _prepare_signup_values(self, qcontext):
values = super()._prepare_signup_values(qcontext)

Check warning on line 106 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L106

Added line #L106 was not covered by tests
if "fiscal_position_type" in qcontext:
values["fiscal_position_type"] = qcontext["fiscal_position_type"]
return values

Check warning on line 109 in website_account_fiscal_position_partner_type/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/main.py#L108-L109

Added lines #L108 - L109 were not covered by tests
44 changes: 44 additions & 0 deletions website_account_fiscal_position_partner_type/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _
from odoo.http import request

from odoo.addons.portal.controllers.portal import CustomerPortal


class CustomerPortal(CustomerPortal):

CustomerPortal.OPTIONAL_BILLING_FIELDS += ["fiscal_position_type"]

def details_form_validate(self, data):
error, error_message = super().details_form_validate(data)
partner = request.env.user.partner_id

Check warning on line 16 in website_account_fiscal_position_partner_type/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/portal.py#L15-L16

Added lines #L15 - L16 were not covered by tests
if (
not partner.can_edit_vat()
and "fiscal_position_type" in data
and data.get("fiscal_position_type") != partner.fiscal_position_type
):
error["fiscal_position_type"] = "error"
error_message.append(

Check warning on line 23 in website_account_fiscal_position_partner_type/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/portal.py#L22-L23

Added lines #L22 - L23 were not covered by tests
_(
"Changing Partner Type is not allowed once document(s) have "
"been issued for your account. Please contact us directly for"
" this operation."
)
)
return error, error_message

Check warning on line 30 in website_account_fiscal_position_partner_type/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/portal.py#L30

Added line #L30 was not covered by tests

def _prepare_portal_layout_values(self):
vals = super()._prepare_portal_layout_values()
afp_obj = request.env["account.fiscal.position"].sudo()
partner = request.env.user.partner_id
vals.update(

Check warning on line 36 in website_account_fiscal_position_partner_type/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/portal.py#L33-L36

Added lines #L33 - L36 were not covered by tests
{
"fiscpostypevalues": dict(
afp_obj._fields["fiscal_position_type"].selection
),
"fiscal_position_type_selected": partner.fiscal_position_type,
}
)
return vals

Check warning on line 44 in website_account_fiscal_position_partner_type/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/controllers/portal.py#L44

Added line #L44 was not covered by tests
22 changes: 22 additions & 0 deletions website_account_fiscal_position_partner_type/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_account_fiscal_position_partner_type
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-10-20 14:35+0000\n"
"Last-Translator: Harald Panten <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: website_account_fiscal_position_partner_type
#: model_terms:ir.ui.view,arch_db:website_account_fiscal_position_partner_type.address_fiscal_position_type
msgid "Partner Type"
msgstr "Tipo de cliente"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_account_fiscal_position_partner_type
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \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: website_account_fiscal_position_partner_type
#: model_terms:ir.ui.view,arch_db:website_account_fiscal_position_partner_type.address_fiscal_position_type
msgid "Partner Type"
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2023 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import res_users
from . import res_partner
15 changes: 15 additions & 0 deletions website_account_fiscal_position_partner_type/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3).

from odoo import api, models


class Partner(models.Model):
_inherit = "res.partner"

@api.model
def signup_retrieve_info(self, token):
res = super().signup_retrieve_info(token)
partner = self._signup_retrieve_partner(token, raise_exception=True)
res.update({"fiscal_position_type_selected": partner.fiscal_position_type})
return res

Check warning on line 15 in website_account_fiscal_position_partner_type/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_partner.py#L12-L15

Added lines #L12 - L15 were not covered by tests
29 changes: 29 additions & 0 deletions website_account_fiscal_position_partner_type/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3).

from odoo import api, models


class ResUsers(models.Model):
_inherit = "res.users"

@api.model
def signup(self, values, token=None):
if token:
partner = self.env["res.partner"]._signup_retrieve_partner(

Check warning on line 13 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L13

Added line #L13 was not covered by tests
token, check_validity=True, raise_exception=True
)
partner_user = partner.user_ids and partner.user_ids[0] or False

Check warning on line 16 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L16

Added line #L16 was not covered by tests
# Don't update fiscal_position_type if partner related to user
# exists (i.e. when resetting password)
if partner_user:
values.pop("fiscal_position_type", None)
return super().signup(values, token)

Check warning on line 21 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L20-L21

Added lines #L20 - L21 were not covered by tests

def _create_user_from_template(self, values):
user = super()._create_user_from_template(values)

Check warning on line 24 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L24

Added line #L24 was not covered by tests
if user and user.partner_id and values.get("fiscal_position_type"):
user.partner_id.write(

Check warning on line 26 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L26

Added line #L26 was not covered by tests
{"fiscal_position_type": values.get("fiscal_position_type")}
)
return user

Check warning on line 29 in website_account_fiscal_position_partner_type/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

website_account_fiscal_position_partner_type/models/res_users.py#L29

Added line #L29 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Sygel <https://www.sygel.es>`_:

* Harald Panten
* Valentin Vinagre
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows e-commerce customers to select if they're end customers or companies.

This module has been designed to be used according the EU One-Stop-Shop in combination with l10n_eu_oss for helping to differentiate which taxes have to be applied.
5 changes: 5 additions & 0 deletions website_account_fiscal_position_partner_type/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
After allowing e-commerce customers to a free sign up:

#. Once the customer wants to buy a product in the e-commerce, he/she will have to specify the partner type field (End customer/company) before finishing the checkout.

#. Depending on the partner type, the applied taxes to the products may change.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading