Skip to content
Closed
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
95 changes: 95 additions & 0 deletions website_sale_partner_firstname/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=============================
First & Last Name at Checkout
=============================

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

.. |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/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/19.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-19-0/website-19-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=19.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:%2019.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/19.0/website_sale_partner_firstname>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_sale_partner_firstname/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers as controllers
from . import models as models
14 changes: 14 additions & 0 deletions website_sale_partner_firstname/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"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": "19.0.1.0.0",
"website": "https://github.com/OCA/website",
"license": "AGPL-3",
"images": [],
"depends": ["website_sale", "partner_firstname"],
"data": [
"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 as main
47 changes: 47 additions & 0 deletions website_sale_partner_firstname/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from odoo.http import request

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


class CustomerPortalFirstLastName(CustomerPortal):
"""Replace 'name' with firstname/lastname on checkout and portal."""

def _create_or_update_address(self, partner_sudo, **form_data):
"""Synthesize 'name' from firstname/lastname so the base code's
address_values['name'] check doesn't raise a KeyError."""
if "name" not in form_data and (
"firstname" in form_data or "lastname" in form_data
):
firstname = (form_data.get("firstname") or "").strip()
lastname = (form_data.get("lastname") or "").strip()
form_data["name"] = request.env["res.partner"]._get_computed_name(
lastname,
firstname,
)
return super()._create_or_update_address(partner_sudo, **form_data)

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

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

def portal_address_country_info(self, country, address_type, **kw):
"""Update the JS required-fields list for firstname/lastname."""
result = super().portal_address_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
1 change: 1 addition & 0 deletions website_sale_partner_firstname/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner as res_partner
8 changes: 8 additions & 0 deletions website_sale_partner_firstname/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models


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

def _get_frontend_writable_fields(self):
return super()._get_frontend_writable_fields() | {"firstname", "lastname"}
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