2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Primary address fix (#5592)

* Improve management of primary address for a company

- Simplify approach (remove "confirm_primary" field)
- Remove @receiver hook
- Move all logic into Address.save() method

* Make address primary if it is the only one defined for a company

* Update frontend table

* Fix saving logic

* Actually fix it this time

* Fix for unit test

* Another test fix
This commit is contained in:
Oliver
2023-09-23 10:14:59 +10:00
committed by GitHub
parent 6cde460567
commit 324d5929b5
4 changed files with 35 additions and 103 deletions

View File

@ -27,6 +27,7 @@
showFormInput,
thumbnailImage,
wrapButtons,
yesNoLabel,
*/
/* exported
@ -798,45 +799,7 @@ function addressFields(options={}) {
company: {
icon: 'fa-building',
},
primary: {
onEdit: function(val, name, field, opts) {
if (val === false) {
hideFormInput("confirm_primary", opts);
$('#id_confirm_primary').prop("checked", false);
clearFormErrors(opts);
enableSubmitButton(opts, true);
} else if (val === true) {
showFormInput("confirm_primary", opts);
if($('#id_confirm_primary').prop("checked") === false) {
handleFormErrors({'confirm_primary': 'WARNING: Setting this address as primary will remove primary flag from other addresses'}, field, {});
enableSubmitButton(opts, false);
}
}
}
},
confirm_primary: {
help_text: "Confirm",
onEdit: function(val, name, field, opts) {
if (val === true) {
clearFormErrors(opts);
enableSubmitButton(opts, true);
} else if (val === false) {
handleFormErrors({'confirm_primary': 'WARNING: Setting this address as primary will remove primary flag from other addresses'}, field, {});
enableSubmitButton(opts, false);
}
},
css: {
display: 'none'
}
},
primary: {},
title: {},
line1: {
icon: 'fa-map'
@ -984,11 +947,7 @@ function loadAddressTable(table, options={}) {
title: '{% trans "Primary" %}',
switchable: false,
formatter: function(value) {
let checked = '';
if (value == true) {
checked = 'checked="checked"';
}
return `<input type="checkbox" ${checked} disabled="disabled" value="${value? 1 : 0}">`;
return yesNoLabel(value);
}
},
{