changed date from and date to in asset

This commit is contained in:
Ali 2025-11-05 16:14:33 +04:00
parent 27ea136f37
commit 858fd16da1
2 changed files with 31 additions and 44 deletions

View File

@ -113,20 +113,11 @@ def create_custom_fields():
reqd=0
),
# Agricultural Validity Section
dict(
fieldname='agricultural_validity_section',
label='Tax Validity Period',
fieldtype='Section Break',
insert_after='agricultural_tax_article',
collapsible=1,
depends_on='eval:doc.agricultural_tax_article'
),
# Agricultural Validity HTML (прямо под tax article, БЕЗ секции)
dict(
fieldname='agricultural_validity_html',
fieldtype='HTML',
insert_after='agricultural_validity_section',
insert_after='agricultural_tax_article',
depends_on='eval:doc.agricultural_tax_article'
),
@ -195,20 +186,11 @@ def create_custom_fields():
reqd=0
),
# Industrial Validity Section
dict(
fieldname='industrial_validity_section',
label='Tax Validity Period',
fieldtype='Section Break',
insert_after='industrial_tax_article',
collapsible=1,
depends_on='eval:doc.industrial_tax_article'
),
# Industrial Validity HTML (прямо под tax article, БЕЗ секции)
dict(
fieldname='industrial_validity_html',
fieldtype='HTML',
insert_after='industrial_validity_section',
insert_after='industrial_tax_article',
depends_on='eval:doc.industrial_tax_article'
),
@ -232,20 +214,11 @@ def create_custom_fields():
reqd=0
),
# Tax Exempt Validity Section
dict(
fieldname='tax_exempt_validity_section',
label='Tax Validity Period',
fieldtype='Section Break',
insert_after='tax_exempt_tax_article',
collapsible=1,
depends_on='eval:doc.tax_exempt_tax_article'
),
# Tax Exempt Validity HTML (прямо под tax article, БЕЗ секции)
dict(
fieldname='tax_exempt_validity_html',
fieldtype='HTML',
insert_after='tax_exempt_validity_section',
insert_after='tax_exempt_tax_article',
depends_on='eval:doc.tax_exempt_tax_article'
),

View File

@ -1,3 +1,5 @@
// asset.js - ПОЛНЫЙ КОД (JS остается без изменений, так как он уже работает правильно)
frappe.ui.form.on('Asset', {
refresh: function(frm) {
setup_asset_fields(frm);
@ -233,13 +235,15 @@ function render_tax_validity_fields(frm, type) {
}
// Создаем контейнер с нужными классами Frappe
const $container = $('<div class="form-section">').appendTo($wrapper);
const $container = $('<div class="form-section" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid #d1d8dd;">').appendTo($wrapper);
const $row = $('<div class="row">').appendTo($container);
// Создаем 3 колонки для полей
const $col1 = $('<div class="col-sm-4">').appendTo($row);
const $col2 = $('<div class="col-sm-4">').appendTo($row);
const $col3 = $('<div class="col-sm-4">').appendTo($row);
// Создаем 2 колонки для полей (Date From и Date To)
const $col1 = $('<div class="col-sm-6">').appendTo($row);
const $col2 = $('<div class="col-sm-6">').appendTo($row);
// ВАЖНО: Блокируем dirty во время загрузки
frm[`_loading_validity_${type}`] = true;
// Проверяем, есть ли уже сохраненные данные в памяти (приоритет)
let initial_date_from = tax_article.date_from;
@ -267,9 +271,9 @@ function render_tax_validity_fields(frm, type) {
});
date_from_field.set_value(initial_date_from);
// Создаем Duration поле (скрытое и read only)
// Создаем скрытое Duration поле (для хранения данных)
const duration_field = frappe.ui.form.make_control({
parent: $col2,
parent: $('<div style="display:none;">').appendTo($wrapper),
df: {
fieldtype: 'Int',
label: __('Duration (Years)'),
@ -283,7 +287,7 @@ function render_tax_validity_fields(frm, type) {
// Создаем Date To поле (read only)
const date_to_field = frappe.ui.form.make_control({
parent: $col3,
parent: $col2,
df: {
fieldtype: 'Date',
label: __('Date To'),
@ -295,8 +299,8 @@ function render_tax_validity_fields(frm, type) {
date_to_field.set_value(initial_date_to);
// Добавляем информационное сообщение
$('<div class="text-muted small" style="margin-top: 10px; padding-left: 15px;">')
.text(__('Changes will be saved to Tax Article when you save this Asset'))
$('<div class="text-muted small" style="margin-top: 10px;">')
.html('<i class="fa fa-info-circle"></i> ' + __('Changes will be saved to Tax Article when you save this Asset'))
.appendTo($container);
// Сохраняем ссылки на контролы
@ -318,6 +322,11 @@ function render_tax_validity_fields(frm, type) {
date_to: initial_date_to,
duration: initial_duration
};
// Снимаем блокировку dirty после небольшой задержки
setTimeout(() => {
frm[`_loading_validity_${type}`] = false;
}, 100);
}
},
error: function() {
@ -327,6 +336,11 @@ function render_tax_validity_fields(frm, type) {
}
function handle_date_from_change(frm, type) {
// Игнорируем изменения во время загрузки
if (frm[`_loading_validity_${type}`]) {
return;
}
if (!frm._tax_validity_controls || !frm._tax_validity_controls[type]) {
return;
}
@ -407,7 +421,7 @@ function save_tax_validity_data(frm) {
return Promise.resolve();
}
// ===== ОСТАЛЬНЫЕ ФУНКЦИИ =====
// ===== ОСТАЛЬНЫЕ ФУНКЦИИ (БЕЗ ИЗМЕНЕНИЙ) =====
function update_area_field_label(frm) {
let asset_type = frm.doc.custom_asset_type;