Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Odoo 16 Javascript overriding/inheritance

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
javascriptinheritanceoverrideodoo16features
3 Trả lời
12598 Lượt xem
Ảnh đại diện
Ahmad Zarour

How could I inherit/override a function in Odoo 16 javascript example 

In the addons/web/static/src/views/fields/formatters.js there is a function 

export function formatFloat(value, options = {}) {
if (value === false) {
return "";
}
if (options.humanReadable) {
return humanNumber(value, options);
}
const grouping = options.grouping || l10n.grouping;
const thousandsSep = "thousandsSep" in options ? options.thousandsSep : l10n.thousandsSep;
const decimalPoint = "decimalPoint" in options ? options.decimalPoint : l10n.decimalPoint;
let precision;
if (options.digits && options.digits[1] !== undefined) {
precision = options.digits[1];
} else {
precision = 2;
}
const formatted = (value || 0).toFixed(precision).split(".");
formatted[0] = insertThousandsSep(formatted[0], thousandsSep, grouping);
if (options.noTrailingZeros) {
formatted[1] = formatted[1].replace(/0+$/, "");
}
return formatted[1] ? formatted.join(decimalPoint) : formatted[0];
}



How could I inherit/override this function?

0
Ảnh đại diện
Huỷ bỏ
Ahmad Zarour
Tác giả

Dear Ashish,

Thank you for your answer, but Unfortunately, it's not working.

Ảnh đại diện
PengXu
Câu trả lời hay nhất

i also need override this function, there is a way, it worked for me.

1. create a js file in your module.

struct like :

​module/static/src/js/formatters.js

formatters.js







/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { localization as l10n } from "@web/core/l10n/localization";
import * as formatters from "@web/views/fields/formatters";
import { registry } from "@web/core/registry";
import { intersperse } from "@web/core/utils/strings";


function insertThousandsSep(number, thousandsSep = ",", grouping = []) {
const negative = number[0] === "-";
number = negative ? number.slice(1) : number;
return (negative ? "-" : "") + intersperse(number, grouping, thousandsSep);
}

function humanNumber(number, options = { decimals: 0, minDigits: 1 }) {
const decimals = options.decimals || 0;
const minDigits = options.minDigits || 1;
const d2 = Math.pow(10, decimals);
const numberMagnitude = +number.toExponential().split("e+")[1];
number = Math.round(number * d2) / d2;
// the case numberMagnitude >= 21 corresponds to a number
// better expressed in the scientific format.
if (numberMagnitude >= 21) {
// we do not use number.toExponential(decimals) because we want to
// avoid the possible useless O decimals: 1e.+24 preferred to 1.0e+24
number = Math.round(number * Math.pow(10, decimals - numberMagnitude)) / d2;
return `${number}e+${numberMagnitude}`;
}
// note: we need to call toString here to make sure we manipulate the resulting
// string, not an object with a toString method.
const unitSymbols = _t("kMGTPE").toString();
const sign = Math.sign(number);
number = Math.abs(number);
let symbol = "";
for (let i = unitSymbols.length; i > 0; i--) {
const s = Math.pow(10, i * 3);
if (s <= number / Math.pow(10, minDigits - 1)) {
number = Math.round((number * d2) / s) / d2;
symbol = unitSymbols[i - 1];
break;
}
}
const { decimalPoint, grouping, thousandsSep } = l10n;

// determine if we should keep the decimals (we don't want to display 1,020.02k for 1020020)
const decimalsToKeep = number >= 1000 ? 0 : decimals;
number = sign * number;
const [integerPart, decimalPart] = number.toFixed(decimalsToKeep).split(".");
const int = insertThousandsSep(integerPart, thousandsSep, grouping);
if (!decimalPart) {
return int + symbol;
}
return int + decimalPoint + decimalPart + symbol;
}


function formatFloatNoTrailingZeros(value, options = {}) {
if (value === false) {
return "";
}
if (options.humanReadable) {
return humanNumber(value, options);
}
const grouping = options.grouping || l10n.grouping;
const thousandsSep = "thousandsSep" in options ? options.thousandsSep : l10n.thousandsSep;
const decimalPoint = "decimalPoint" in options ? options.decimalPoint : l10n.decimalPoint;
let precision;
if (options.digits && options.digits[1] !== undefined) {
precision = options.digits[1];
} else {
precision = 2;
}
const formatted = (value || 0).toFixed(precision).split(".");
formatted[0] = insertThousandsSep(formatted[0], thousandsSep, grouping);
formatted[1] = formatted[1].replace(/0+$/, "");
return formatted[1] ? formatted.join(decimalPoint) : formatted[0];
}

patch(formatters, 'module_name.newFormatFloat', {
formatFloat(value, options = {}) {
const format_value = formatFloatNoTrailingZeros(value, options);
return format_value;
}
});

registry.category("formatters").remove('float');
registry.category("formatters").add("float", formatFloatNoTrailingZeros);

2. add assets to your __manifest__.py 

'assets': {
'web.assets_backend': [
'module_name/static/src/js/formatters.js',
]},

and then its work.

But in the end I gave up override the function, then patch function 

ListRendererPatch

its also worked, hope its useful to you

/** @odoo-module **/
import
{ patch } from "@web/core/utils/patch";
import
{ registry } from "@web/core/registry";
import
{ ListRenderer } from "@web/views/list/list_renderer";


const
formatters = registry.category("formatters");

patch(ListRenderer.prototype, 'module_name.ListRendererPatch', {
getFormattedValue(column, record) {
const fieldName = column.name;
const
field = this.fields[fieldName];
const
formatter = formatters.get(field.type, (val) => val);
const
formatOptions = {
escape: false,
data
: record.data,
isPassword
: "password" in column.rawAttrs,
digits
: column.rawAttrs.digits ? JSON.parse(column.rawAttrs.digits) : field.digits,
field
: record.fields[fieldName],
noTrailingZeros
: true,
};
//   options="{'keep_zero': True, 'set_digits': 5}" default noTrailingZeros is true
//  eg :
if
('set_digits' in column.options && formatOptions.digits && formatOptions.digits[1] !== undefined){
formatOptions.digits[1] = column.options.set_digits;
}
if ('keep_zero' in column.options){
formatOptions.noTrailingZeros = !column.options.keep_zero;
}
return formatter(record.data[fieldName], formatOptions);
}
});


0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Nguyễn Ngọc Anh Khoa
Câu trả lời hay nhất

I have the same problem, have you solved this?

0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Ashish Hirpara
Câu trả lời hay nhất

To inherit and override this function in Odoo 16 OWL, you can use the following steps:

  1. Create a new module, for example, my_module.

  2. In your new module, create a file static/src/js/my_module.js and put the following code in it:

import {formatFloat as originalFormatFloat} from 'web/static/src/views/fields/formatters.js';

export function formatFloat(value, options = {}) { // Your custom code here // You can call the original function using originalFormatFloat() }

  1. In your new module, create a file views/assets.xml and put the following code in it:

  1. Install your new module in Odoo.

This will override the formatFloat function in your Odoo instance and use your custom implementation instead. You can modify the code in the my_module.js file to customize the behavior of the function as needed

0
Ảnh đại diện
Huỷ bỏ
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
Odoo16 Owl Js Function override
javascript inheritance override OWL odoo16features
Ảnh đại diện
Ảnh đại diện
1
thg 10 23
4042
[v15] header: change selector for cart popup Đã xử lý
javascript inheritance override website_sale
Ảnh đại diện
Ảnh đại diện
2
thg 12 22
3470
Can't log the console inside the include javascript Odoo v16 Đã xử lý
javascript odoo16features
Ảnh đại diện
Ảnh đại diện
1
thg 4 24
3054
Odoo 16.0 CE - Missing widget: radio_reduce_selection for field of type selection
javascript odoo16features
Ảnh đại diện
0
thg 1 24
2569
What is the Best Practice for Integrating JavaScript in Odoo 16?
javascript odoo16features
Ảnh đại diện
Ảnh đại diện
1
thg 9 23
4156
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now