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
91 changes: 91 additions & 0 deletions website_sale_partner_firstname/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=============================
First & Last Name at Checkout
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2f71726af23fd6e4ec9092479bf6088ba852635f250840a2a17039c8858eec7b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/18.0/website_sale_partner_firstname
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-18-0/website-18-0-website_sale_partner_firstname
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=18.0
:alt: Try me on Runboat

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

This module extends the website checkout and portal to use separate
first name and last name fields, leveraging the ``partner_firstname``
module for name splitting.

**Table of contents**

.. contents::
:local:

Usage
=====

Once installed, the single "Name" field is automatically replaced by
separate "First name" and "Last name" fields on:

- The checkout address form (``/shop/address``)
- The portal account details page (``/my/account``)

Both fields are mandatory. Whitespace-only values are rejected.

No configuration is required.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_sale_partner_firstname%0Aversion:%2018.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
-------

* Aaron Ngu

Contributors
------------

- Aaron Ngu <aaron@swimmingchicken.com>

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/website <https://github.com/OCA/website/tree/18.0/website_sale_partner_firstname>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions website_sale_partner_firstname/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
15 changes: 15 additions & 0 deletions website_sale_partner_firstname/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "First & Last Name at Checkout",
"summary": "Separate first and last name fields at checkout and portal",
"author": "Aaron Ngu, Odoo Community Association (OCA)",
"category": "Website/Website",
"version": "18.0.1.0.0",
"website": "https://github.com/OCA/website",
"license": "AGPL-3",
"images": [],
"depends": ["website_sale", "partner_firstname"],
"data": [
"data/res_partner_data.xml",
"views/templates.xml",
],
}
1 change: 1 addition & 0 deletions website_sale_partner_firstname/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
63 changes: 63 additions & 0 deletions website_sale_partner_firstname/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from odoo.http import route

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


class WebsiteSaleFirstLastName(WebsiteSale):
"""Replace 'name' with firstname/lastname on checkout/portal."""

# -------------------------------------------------------------------------
# Shared (affects both checkout and portal)
# -------------------------------------------------------------------------

def _get_mandatory_fields(self):
"""Swap 'name' for 'firstname' and 'lastname' in mandatory fields."""
mandatory_fields = super()._get_mandatory_fields()
if "name" in mandatory_fields:
mandatory_fields.remove("name")
mandatory_fields.extend(["firstname", "lastname"])
return mandatory_fields

# -------------------------------------------------------------------------
# Portal /my/account
# -------------------------------------------------------------------------

def details_form_validate(self, data, *args, **kwargs):
"""Strip whitespace from name fields so blank strings fail validation."""
for field in ("firstname", "lastname"):
if field in data and isinstance(data[field], str):
data[field] = data[field].strip()
return super().details_form_validate(data, *args, **kwargs)

def on_account_update(self, values, partner):
"""Ensure 'name' is present to prevent KeyError in bank-holder check."""
result = super().on_account_update(values, partner)
# With partner_firstname, name is computed from firstname/lastname,
# so set the current name to prevent KeyError.
if "name" not in values:
values["name"] = partner.name or ""
return result

# -------------------------------------------------------------------------
# Checkout /shop/address
# -------------------------------------------------------------------------

def _get_mandatory_address_fields(self, country_sudo):
"""Swap 'name' for 'firstname' and 'lastname' in mandatory address fields."""
mandatory_fields = super()._get_mandatory_address_fields(country_sudo)
mandatory_fields.discard("name")
mandatory_fields |= {"firstname", "lastname"}
return mandatory_fields

@route()
def shop_country_info(self, country, address_type, **kw):
"""Update the JS required-fields list for firstname/lastname."""
result = super().shop_country_info(country, address_type, **kw)
if "required_fields" in result:
result["required_fields"] = [
f for f in result["required_fields"] if f != "name"
]
for field in ("firstname", "lastname"):
if field not in result["required_fields"]:
result["required_fields"].append(field)
return result
7 changes: 7 additions & 0 deletions website_sale_partner_firstname/data/res_partner_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>res.partner</value>
<value eval="['firstname', 'lastname']" />
</function>
</odoo>
1 change: 1 addition & 0 deletions website_sale_partner_firstname/oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partner-contact
3 changes: 3 additions & 0 deletions website_sale_partner_firstname/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions website_sale_partner_firstname/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Aaron Ngu \<aaron@swimmingchicken.com\>
3 changes: 3 additions & 0 deletions website_sale_partner_firstname/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module extends the website checkout and portal to use separate
first name and last name fields, leveraging the `partner_firstname`
module for name splitting.
9 changes: 9 additions & 0 deletions website_sale_partner_firstname/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Once installed, the single "Name" field is automatically replaced by
separate "First name" and "Last name" fields on:

- The checkout address form (`/shop/address`)
- The portal account details page (`/my/account`)

Both fields are mandatory. Whitespace-only values are rejected.

No configuration is required.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading