added 4 columns to sales order and sales invoice, and added item tax template fixtures
This commit is contained in:
parent
8ee4e1ba73
commit
0f85522ab6
|
|
@ -1124,14 +1124,11 @@ window.ETaxesCompany = {
|
|||
const profile = profileData.profile || profileData;
|
||||
const updates = ETaxesCompany._parseProfileData(profile, frm);
|
||||
|
||||
// Проверяем есть ли дополнительные данные для обновления
|
||||
const hasAdditionalActivities = profile.additionalActivityCodes && profile.additionalActivityCodes.length > 0;
|
||||
const hasAffiliates = profile.affiliatesNames && profile.affiliatesNames.length > 0;
|
||||
const hasDictionaryFields = profile.taxAuthorityCode || profile.propertyType;
|
||||
|
||||
// Если есть обновления полей или дополнительные данные
|
||||
if (updates.length > 0 || hasAdditionalActivities || hasAffiliates || hasDictionaryFields) {
|
||||
// Формируем сообщение для подтверждения
|
||||
let confirmMessage = '';
|
||||
|
||||
if (updates.length > 0) {
|
||||
|
|
@ -1144,7 +1141,6 @@ window.ETaxesCompany = {
|
|||
confirmMessage += changesList;
|
||||
}
|
||||
|
||||
// Добавляем информацию о дополнительных данных
|
||||
let additionalInfo = '';
|
||||
if (hasAdditionalActivities) {
|
||||
additionalInfo += `<br><strong>${__('Additional activities to be added')}:</strong> ${profile.additionalActivityCodes.length} ${__('activities')}`;
|
||||
|
|
@ -1163,42 +1159,60 @@ window.ETaxesCompany = {
|
|||
frappe.confirm(
|
||||
confirmMessage,
|
||||
function() {
|
||||
// ВАЖНО: Отключаем автосохранение перед массовыми изменениями
|
||||
frm.disable_save();
|
||||
|
||||
// Apply all field updates
|
||||
// Собираем все обновления полей
|
||||
let allUpdates = {};
|
||||
updates.forEach(update => {
|
||||
frm.set_value(update.fieldname, update.newValue);
|
||||
allUpdates[update.fieldname] = update.newValue;
|
||||
});
|
||||
|
||||
// Обновляем поля из справочников
|
||||
if (hasDictionaryFields) {
|
||||
ETaxesCompany._updateDictionaryFields(profile, frm);
|
||||
// Обрабатываем справочники
|
||||
let promises = [];
|
||||
|
||||
if (profile.taxAuthorityCode) {
|
||||
promises.push(
|
||||
ETaxesCompany._getTaxAuthorityName(profile.taxAuthorityCode).then((authorityName) => {
|
||||
allUpdates['tax_authority'] = authorityName;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Задержка перед обновлением табличных частей
|
||||
setTimeout(function() {
|
||||
// Обновляем дополнительные активности
|
||||
if (hasAdditionalActivities) {
|
||||
ETaxesCompany._updateAdditionalActivities(profile, frm);
|
||||
if (profile.propertyType) {
|
||||
promises.push(
|
||||
ETaxesCompany._getPropertyTypeName(profile.propertyType).then((propertyTypeName) => {
|
||||
allUpdates['property_type'] = propertyTypeName;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Обновляем дочерние организации
|
||||
if (hasAffiliates) {
|
||||
ETaxesCompany._updateAffiliateOrganizations(profile, frm);
|
||||
}
|
||||
Promise.all(promises).then(() => {
|
||||
// Вызываем серверный метод для форсированного обновления
|
||||
frappe.call({
|
||||
method: 'taxes_az.company_etaxes.force_update_company',
|
||||
args: {
|
||||
company_name: frm.doc.name,
|
||||
field_updates: allUpdates,
|
||||
additional_activities: hasAdditionalActivities ? profile.additionalActivityCodes : [],
|
||||
affiliate_names: hasAffiliates ? profile.affiliatesNames : [],
|
||||
affiliate_tins: hasAffiliates ? profile.affiliatesTins : []
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message && r.message.success) {
|
||||
// Перезагружаем форму
|
||||
frm.reload_doc();
|
||||
|
||||
// Включаем сохранение обратно и сохраняем
|
||||
setTimeout(function() {
|
||||
frm.enable_save();
|
||||
frm.save('Update', function() {
|
||||
frappe.show_alert({
|
||||
message: __('Company data updated from E-Taxes profile'),
|
||||
message: __('Company data force updated from E-Taxes profile'),
|
||||
indicator: 'green'
|
||||
}, 5);
|
||||
} else {
|
||||
frappe.msgprint(__('Error updating company data'));
|
||||
}
|
||||
},
|
||||
error: function(r) {
|
||||
frappe.msgprint(__('Server error during update'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 500);
|
||||
}, 300);
|
||||
},
|
||||
function() {
|
||||
frappe.show_alert({
|
||||
|
|
|
|||
|
|
@ -450,3 +450,90 @@ def get_default_asan_login():
|
|||
|
||||
except Exception as e:
|
||||
return {"found": False, "error": str(e)}
|
||||
|
||||
@frappe.whitelist()
|
||||
def force_update_company(company_name, field_updates=None, additional_activities=None, affiliate_names=None, affiliate_tins=None):
|
||||
"""Форсированное обновление полей компании через прямые SQL-запросы"""
|
||||
import json
|
||||
|
||||
# Парсим JSON если нужно
|
||||
if isinstance(field_updates, str):
|
||||
field_updates = json.loads(field_updates) if field_updates else {}
|
||||
if isinstance(additional_activities, str):
|
||||
additional_activities = json.loads(additional_activities) if additional_activities else []
|
||||
if isinstance(affiliate_names, str):
|
||||
affiliate_names = json.loads(affiliate_names) if affiliate_names else []
|
||||
if isinstance(affiliate_tins, str):
|
||||
affiliate_tins = json.loads(affiliate_tins) if affiliate_tins else []
|
||||
|
||||
# Обновляем основные поля через SQL
|
||||
if field_updates:
|
||||
set_clauses = []
|
||||
values = []
|
||||
|
||||
for field, value in field_updates.items():
|
||||
set_clauses.append(f"`{field}` = %s")
|
||||
values.append(value)
|
||||
|
||||
if set_clauses:
|
||||
values.append(company_name)
|
||||
sql = f"""
|
||||
UPDATE `tabCompany`
|
||||
SET {', '.join(set_clauses)}, `modified` = NOW(), `modified_by` = %s
|
||||
WHERE `name` = %s
|
||||
"""
|
||||
values.append(frappe.session.user)
|
||||
values.append(company_name)
|
||||
|
||||
frappe.db.sql(sql, tuple(values))
|
||||
|
||||
# Удаляем старые записи в табличных частях
|
||||
frappe.db.sql("""DELETE FROM `tabAdditional Activity Types` WHERE parent = %s""", company_name)
|
||||
frappe.db.sql("""DELETE FROM `tabAffiliate Organizations` WHERE parent = %s""", company_name)
|
||||
|
||||
# Добавляем новые additional activities
|
||||
if additional_activities:
|
||||
for idx, activity_code in enumerate(additional_activities):
|
||||
if activity_code and activity_code.strip():
|
||||
# Проверяем существование Main type of activity
|
||||
if frappe.db.exists("Main type of activity", activity_code.strip()):
|
||||
frappe.db.sql("""
|
||||
INSERT INTO `tabAdditional Activity Types`
|
||||
(name, parent, parenttype, parentfield, idx, activity_type, docstatus)
|
||||
VALUES (%s, %s, 'Company', 'additional_activity_types', %s, %s, 1)
|
||||
""", (
|
||||
frappe.generate_hash(length=10),
|
||||
company_name,
|
||||
idx + 1,
|
||||
activity_code.strip()
|
||||
))
|
||||
|
||||
# Добавляем новые affiliate organizations
|
||||
if affiliate_names or affiliate_tins:
|
||||
max_length = max(len(affiliate_names or []), len(affiliate_tins or []))
|
||||
for idx in range(max_length):
|
||||
org_name = affiliate_names[idx] if affiliate_names and idx < len(affiliate_names) else ""
|
||||
org_tin = affiliate_tins[idx] if affiliate_tins and idx < len(affiliate_tins) else ""
|
||||
|
||||
if org_name or org_tin:
|
||||
if not org_name and org_tin:
|
||||
org_name = f"Organization (TIN: {org_tin})"
|
||||
|
||||
frappe.db.sql("""
|
||||
INSERT INTO `tabAffiliate Organizations`
|
||||
(name, parent, parenttype, parentfield, idx, organization_name, organization_tin, docstatus)
|
||||
VALUES (%s, %s, 'Company', 'affiliate_organizations', %s, %s, %s, 1)
|
||||
""", (
|
||||
frappe.generate_hash(length=10),
|
||||
company_name,
|
||||
idx + 1,
|
||||
org_name,
|
||||
org_tin or None
|
||||
))
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
# Очищаем кэш
|
||||
frappe.clear_cache(doctype="Company")
|
||||
|
||||
return {"success": True, "message": "Company updated successfully"}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,51 @@
|
|||
[
|
||||
{
|
||||
"company": "Ali Pupu",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Item Tax Template",
|
||||
"modified": "2025-08-22 14:39:02.957015",
|
||||
"name": "ƏDV-dən azadolma",
|
||||
"taxes": [
|
||||
{
|
||||
"tax_rate": 0.0,
|
||||
"tax_type": "521.3 - ƏDV - AP"
|
||||
}
|
||||
],
|
||||
"title": "ƏDV-dən azadolma"
|
||||
},
|
||||
{
|
||||
"company": "Ali Pupu",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Item Tax Template",
|
||||
"modified": "2025-08-22 14:35:17.356794",
|
||||
"name": "ƏDV 0%",
|
||||
"taxes": [
|
||||
{
|
||||
"tax_rate": 0.0,
|
||||
"tax_type": "521.3 - ƏDV"
|
||||
}
|
||||
],
|
||||
"title": "ƏDV 0%"
|
||||
},
|
||||
{
|
||||
"company": "Ali Pupu",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Item Tax Template",
|
||||
"modified": "2025-08-22 14:38:38.387654",
|
||||
"name": "ƏDV 18%",
|
||||
"taxes": [
|
||||
{
|
||||
"tax_rate": 18.0,
|
||||
"tax_type": "521.3 - ƏDV"
|
||||
},
|
||||
{
|
||||
"tax_rate": 20.0,
|
||||
"tax_type": "521.7 - Yol vergisi"
|
||||
}
|
||||
],
|
||||
"title": "ƏDV 18%"
|
||||
}
|
||||
]
|
||||
|
|
@ -31,6 +31,10 @@ fixtures = [
|
|||
{
|
||||
"doctype": "Business Classification",
|
||||
"filters": []
|
||||
},
|
||||
{
|
||||
"doctype": "Item Tax Template",
|
||||
"filters": []
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue