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

[16.0][ADD] sale_end_customer #3567

Open
wants to merge 1 commit into
base: 16.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
95 changes: 95 additions & 0 deletions sale_end_customer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
=================
Sale End Customer
=================

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

.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_end_customer
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_end_customer
: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/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

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

This module introduces the End Customer field in sales orders and customer invoices.
This field is accounted for in sales and invoice analysis reports.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

There are trade flows where your direct customer is not the end customer of the sold
products (e.g., you sell to a dealer, and the dealer sells to the end customer). In such
cases, you may want to record the end customers in your sales transactions.

Usage
=====

Enter the end customer field in the sales order as appropriate. The assigned value will
be passed to the corresponding field in the customer invoice when the invoice is
created.

If an invoice involves multiple sales orders with different end customers, the end
customer from the last processed sales order will prevail.

Known issues / Roadmap
======================

The module currently does not adjust the invoice grouping keys (`sale.order._get_invoice_grouping_keys()`)
to include the end customer field.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_end_customer%0Aversion:%2016.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
~~~~~~~

* Quartile

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/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_end_customer>`_ 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 sale_end_customer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import reports
18 changes: 18 additions & 0 deletions sale_end_customer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale End Customer",
"version": "16.0.1.0.0",
"category": "Sale",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["sale"],
"license": "AGPL-3",
"data": [
"reports/account_invoice_report_views.xml",
"reports/sale_report_views.xml",
"views/account_move_views.xml",
"views/sale_order_views.xml",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions sale_end_customer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move
from . import sale_order
15 changes: 15 additions & 0 deletions sale_end_customer/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountMove(models.Model):
_inherit = "account.move"

partner_end_customer_id = fields.Many2one(
"res.partner",
string="End Customer",
tracking=True,
check_company=True,
)
20 changes: 20 additions & 0 deletions sale_end_customer/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class SaleOrder(models.Model):
_inherit = "sale.order"

partner_end_customer_id = fields.Many2one(
"res.partner",
string="End Customer",
tracking=True,
check_company=True,
)

def _prepare_invoice(self):
invoice_vals = super()._prepare_invoice()
invoice_vals["partner_end_customer_id"] = self.partner_end_customer_id.id
return invoice_vals
3 changes: 3 additions & 0 deletions sale_end_customer/readme/CONTEXT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
There are trade flows where your direct customer is not the end customer of the sold
products (e.g., you sell to a dealer, and the dealer sells to the end customer). In such
cases, you may want to record the end customers in your sales transactions.
2 changes: 2 additions & 0 deletions sale_end_customer/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module introduces the End Customer field in sales orders and customer invoices.
This field is accounted for in sales and invoice analysis reports.
2 changes: 2 additions & 0 deletions sale_end_customer/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The module currently does not adjust the invoice grouping keys (`sale.order._get_invoice_grouping_keys()`)
to include the end customer field.
6 changes: 6 additions & 0 deletions sale_end_customer/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enter the end customer field in the sales order as appropriate. The assigned value will
be passed to the corresponding field in the customer invoice when the invoice is
created.

If an invoice involves multiple sales orders with different end customers, the end
customer from the last processed sales order will prevail.
2 changes: 2 additions & 0 deletions sale_end_customer/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_invoice_report
from . import sale_report
17 changes: 17 additions & 0 deletions sale_end_customer/reports/account_invoice_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountInvoiceReport(models.Model):
_inherit = "account.invoice.report"

partner_end_customer_id = fields.Many2one("res.partner", string="End Customer")

def _select(self):
select_str = super()._select()
select_str += """
, move.partner_end_customer_id as partner_end_customer_id
"""
return select_str
16 changes: 16 additions & 0 deletions sale_end_customer/reports/account_invoice_report_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_account_invoice_report_search" model="ir.ui.view">
<field name="inherit_id" ref="account.view_account_invoice_report_search" />
<field name="model">account.invoice.report</field>
<field name="arch" type="xml">
<filter name="user" position="after">
<filter
string="End Customer"
name="partner_end_customer_id"
context="{'group_by':'partner_end_customer_id'}"
/>
</filter>
</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions sale_end_customer/reports/sale_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class SaleReport(models.Model):
_inherit = "sale.report"

partner_end_customer_id = fields.Many2one("res.partner", string="End Customer")

def _select_additional_fields(self):
res = super()._select_additional_fields()
res["partner_end_customer_id"] = "s.partner_end_customer_id"
return res

def _group_by_sale(self):
res = super()._group_by_sale()
res += """,
s.partner_end_customer_id"""
return res
16 changes: 16 additions & 0 deletions sale_end_customer/reports/sale_report_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_order_product_search" model="ir.ui.view">
<field name="inherit_id" ref="sale.view_order_product_search" />
<field name="model">sale.report</field>
<field name="arch" type="xml">
<filter name="User" position="after">
<filter
string="End Customer"
name="partner_end_customer_id"
context="{'group_by':'partner_end_customer_id'}"
/>
</filter>
</field>
</record>
</odoo>
Loading