first commit
This commit is contained in:
commit
84ae87fdcf
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
16
__manifest__.py
Normal file
16
__manifest__.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
'name': 'POS Customer Orders',
|
||||||
|
'version': '17.0.1.0.0',
|
||||||
|
'category': 'Point of Sale',
|
||||||
|
'summary': 'Show last 2 orders in POS Customer Details',
|
||||||
|
'depends': ['point_of_sale'],
|
||||||
|
'data': [],
|
||||||
|
'assets': {
|
||||||
|
'point_of_sale.assets_prod': [
|
||||||
|
'pos_customer_orders/static/src/xml/**/*',
|
||||||
|
'pos_customer_orders/static/src/js/**/*',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'installable': True,
|
||||||
|
'application': False,
|
||||||
|
}
|
||||||
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
1
models/__init__.py
Normal file
1
models/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import res_partner
|
||||||
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/res_partner.cpython-312.pyc
Normal file
BIN
models/__pycache__/res_partner.cpython-312.pyc
Normal file
Binary file not shown.
27
models/res_partner.py
Normal file
27
models/res_partner.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_pos_last_orders(self, partner_id):
|
||||||
|
orders = self.env['pos.order'].search(
|
||||||
|
[('partner_id', '=', partner_id)],
|
||||||
|
order='date_order desc',
|
||||||
|
limit=2
|
||||||
|
)
|
||||||
|
return [{
|
||||||
|
'id': order.id,
|
||||||
|
'name': order.name,
|
||||||
|
'pos_reference': order.pos_reference,
|
||||||
|
'date_order': order.date_order,
|
||||||
|
'amount_total': order.amount_total,
|
||||||
|
'note': order.note,
|
||||||
|
'lines': [{
|
||||||
|
'id': line.id,
|
||||||
|
'product_name': line.product_id.name,
|
||||||
|
'qty': line.qty,
|
||||||
|
'price_unit': line.price_unit,
|
||||||
|
'price_subtotal_incl': line.price_subtotal_incl,
|
||||||
|
} for line in order.lines],
|
||||||
|
} for order in orders]
|
||||||
30
static/src/js/partner_editor.js
Normal file
30
static/src/js/partner_editor.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/** @odoo-module */
|
||||||
|
|
||||||
|
import { PartnerDetailsEdit } from "@point_of_sale/app/screens/partner_list/partner_editor/partner_editor";
|
||||||
|
import { patch } from "@web/core/utils/patch";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { onWillStart, useState } from "@odoo/owl";
|
||||||
|
|
||||||
|
patch(PartnerDetailsEdit.prototype, {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.state = useState({ ...this.state, lastOrders: [] });
|
||||||
|
|
||||||
|
onWillStart(async () => {
|
||||||
|
await this.fetchLastOrders();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchLastOrders() {
|
||||||
|
const partnerId = this.props.partner.id;
|
||||||
|
if (partnerId) {
|
||||||
|
try {
|
||||||
|
const orders = await this.orm.call("res.partner", "get_pos_last_orders", [partnerId]);
|
||||||
|
this.state.lastOrders = orders;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching orders:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
42
static/src/xml/partner_editor.xml
Normal file
42
static/src/xml/partner_editor.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates id="template" xml:space="preserve">
|
||||||
|
|
||||||
|
<t t-name="pos_customer_orders.PartnerDetailsEdit" t-inherit="point_of_sale.PartnerDetailsEdit" t-inherit-mode="extension">
|
||||||
|
<xpath expr="//section" position="after">
|
||||||
|
<section class="partner-details-orders d-flex flex-column m-3">
|
||||||
|
<div class="container">
|
||||||
|
<h3 class="mb-3">Last Orders</h3>
|
||||||
|
<t t-if="state.lastOrders and state.lastOrders.length > 0">
|
||||||
|
<div class="list-group">
|
||||||
|
<t t-foreach="state.lastOrders" t-as="order" t-key="order.id">
|
||||||
|
<div class="list-group-item list-group-item-action flex-column align-items-start">
|
||||||
|
<div class="d-flex w-100 justify-content-between">
|
||||||
|
<h5 class="mb-1"><t t-esc="order.pos_reference || order.name"/></h5>
|
||||||
|
<small class="text-muted"><t t-esc="order.date_order"/></small>
|
||||||
|
</div>
|
||||||
|
<p class="mb-1">Total: <t t-esc="env.utils.formatCurrency(order.amount_total)"/></p>
|
||||||
|
<small class="text-muted" t-if="order.note">Note: <t t-esc="order.note"/></small>
|
||||||
|
<div class="mt-2" t-if="order.lines and order.lines.length > 0">
|
||||||
|
<small class="fw-bold">Products:</small>
|
||||||
|
<ul class="list-unstyled small ps-2">
|
||||||
|
<t t-foreach="order.lines" t-as="line" t-key="line.id">
|
||||||
|
<li>
|
||||||
|
<t t-esc="line.qty"/> x <t t-esc="line.product_name"/>
|
||||||
|
(<t t-esc="env.utils.formatCurrency(line.price_subtotal_incl)"/>)
|
||||||
|
</li>
|
||||||
|
</t>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
<t t-else="">
|
||||||
|
<div class="alert alert-info">No orders found for this customer.</div>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
</templates>
|
||||||
Loading…
Reference in New Issue
Block a user