forked from verdnatura/salix-front
Compare commits
4 Commits
dev
...
hotfix_ite
Author | SHA1 | Date |
---|---|---|
|
dc13096bc1 | |
|
477404f00a | |
|
4a346bd5d0 | |
|
40f7ccf42b |
|
@ -246,7 +246,7 @@ function getChanges() {
|
|||
for (const [i, row] of formData.value.entries()) {
|
||||
if (!row[pk]) {
|
||||
creates.push(row);
|
||||
} else if (originalData.value) {
|
||||
} else if (originalData.value[i]) {
|
||||
const data = getDifferences(originalData.value[i], row);
|
||||
if (!isEmpty(data)) {
|
||||
updates.push({
|
||||
|
|
|
@ -211,8 +211,6 @@ const getRowUpdateInputEvents = (props, resetMinPrice, inputType = 'text') => {
|
|||
};
|
||||
|
||||
const updateMinPrice = async (value, props) => {
|
||||
// El checkbox hasMinPrice se encuentra en la misma columna que el input hasMinPrice
|
||||
// Por lo tanto le mandamos otro objeto con las mismas propiedades pero con el campo 'field' cambiado
|
||||
props.row.hasMinPrice = value;
|
||||
await upsertPrice({
|
||||
row: props.row,
|
||||
|
@ -221,13 +219,36 @@ const updateMinPrice = async (value, props) => {
|
|||
});
|
||||
};
|
||||
|
||||
const validations = ({ row }) => {
|
||||
const isNew = !row.id;
|
||||
if (!isNew) return false;
|
||||
|
||||
const requiredFields = [
|
||||
'itemFk',
|
||||
'started',
|
||||
'ended',
|
||||
'rate2',
|
||||
'rate3',
|
||||
'warehouseFk',
|
||||
];
|
||||
const isValid = requiredFields.every(
|
||||
(field) => row[field] !== null && row[field] !== undefined
|
||||
);
|
||||
return isValid;
|
||||
};
|
||||
const upsertPrice = async (props, resetMinPrice = false) => {
|
||||
try {
|
||||
const { row } = props;
|
||||
if (tableRef.value.CrudModelRef.getChanges().updates.length > 0) {
|
||||
if (resetMinPrice) row.hasMinPrice = 0;
|
||||
await upsertFixedPrice(row);
|
||||
const isValid = validations({ ...props });
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
const { row } = props;
|
||||
const changes = tableRef.value.CrudModelRef.getChanges();
|
||||
if (changes?.updates?.length > 0) {
|
||||
if (resetMinPrice) row.hasMinPrice = 0;
|
||||
}
|
||||
const data = await upsertFixedPrice(row);
|
||||
tableRef.value.CrudModelRef.formData[props.rowIndex] = data;
|
||||
} catch (err) {
|
||||
console.error('Error editing price', err);
|
||||
}
|
||||
|
@ -242,13 +263,6 @@ async function upsertFixedPrice(row) {
|
|||
}
|
||||
}
|
||||
|
||||
async function saveOnRowChange(row) {
|
||||
if (rowsSelected.value.length > 1) return;
|
||||
if (rowsSelected.value[0]?.id === row.id) return;
|
||||
else if (rowsSelected.value.length === 1) await upsertPrice(rowsSelected.value[0]);
|
||||
rowsSelected.value = [row];
|
||||
}
|
||||
|
||||
function checkLastVisibleRow() {
|
||||
let lastVisibleRow = null;
|
||||
|
||||
|
@ -264,39 +278,18 @@ function checkLastVisibleRow() {
|
|||
|
||||
const addRow = (original = null) => {
|
||||
let copy = null;
|
||||
if (!original) {
|
||||
const today = Date.vnNew();
|
||||
const millisecsInDay = 86400000;
|
||||
const daysInWeek = 7;
|
||||
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||
const today = Date.vnNew();
|
||||
const millisecsInDay = 86400000;
|
||||
const daysInWeek = 7;
|
||||
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||
|
||||
copy = {
|
||||
id: 0,
|
||||
started: today,
|
||||
ended: nextWeek,
|
||||
hasMinPrice: 0,
|
||||
$index: 0,
|
||||
};
|
||||
} else
|
||||
copy = {
|
||||
$index: original.$index - 1,
|
||||
itemFk: original.itemFk,
|
||||
name: original.name,
|
||||
subName: original.subName,
|
||||
value5: original.value5,
|
||||
value6: original.value6,
|
||||
value7: original.value7,
|
||||
value8: original.value8,
|
||||
value9: original.value9,
|
||||
value10: original.value10,
|
||||
warehouseFk: original.warehouseFk,
|
||||
rate2: original.rate2,
|
||||
rate3: original.rate3,
|
||||
hasMinPrice: original.hasMinPrice,
|
||||
minPrice: original.minPrice,
|
||||
started: Date.vnNew(),
|
||||
ended: Date.vnNew(),
|
||||
};
|
||||
copy = {
|
||||
id: 0,
|
||||
started: today,
|
||||
ended: nextWeek,
|
||||
hasMinPrice: 0,
|
||||
$index: 0,
|
||||
};
|
||||
return { original, copy };
|
||||
};
|
||||
|
||||
|
@ -309,7 +302,7 @@ function highlightNewRow({ $index: index }) {
|
|||
row.classList.add('highlight');
|
||||
setTimeout(() => {
|
||||
row.classList.remove('highlight');
|
||||
}, 3000); // Duración de la animación en milisegundos
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
const openEditTableCellDialog = () => {
|
||||
|
@ -436,15 +429,10 @@ function handleOnDataSave({ CrudModelRef }) {
|
|||
auto-load
|
||||
:is-editable="true"
|
||||
:right-search="false"
|
||||
:table="{
|
||||
'row-key': 'id',
|
||||
selection: 'multiple',
|
||||
}"
|
||||
:crud-model="{
|
||||
paginate: false,
|
||||
}"
|
||||
v-model:selected="rowsSelected"
|
||||
:row-click="saveOnRowChange"
|
||||
:create-as-dialog="false"
|
||||
:create="{
|
||||
onDataSaved: handleOnDataSave,
|
||||
|
@ -585,7 +573,18 @@ function handleOnDataSave({ CrudModelRef }) {
|
|||
</QIcon>
|
||||
</template>
|
||||
</VnTable>
|
||||
<!-- <QPageSticky v-if="rowsSelected" :offset="[20, 80]" style="z-index: 2">
|
||||
<QBtn
|
||||
|
||||
@click="makeInvoice(selectedRows)"
|
||||
color="primary"
|
||||
fab
|
||||
icon="vn:invoice-in"
|
||||
/>
|
||||
<QTooltip>
|
||||
{{ t('ticketList.createInvoice') }}
|
||||
</QTooltip>
|
||||
</QPageSticky>-->
|
||||
<QDialog ref="editTableCellDialogRef">
|
||||
<EditTableCellValueForm
|
||||
edit-url="FixedPrices/editFixedPrice"
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/// <reference types="cypress" />
|
||||
describe('Handle Items FixedPrice', () => {
|
||||
beforeEach(() => {
|
||||
cy.viewport(1280, 720);
|
||||
cy.login('developer');
|
||||
cy.visit('/#/item/fixed-price', { timeout: 5000 });
|
||||
cy.waitForElement('.q-table');
|
||||
});
|
||||
it('Create and delete', function () {
|
||||
cy.get(
|
||||
'.q-header > .q-toolbar > :nth-child(1) > .q-btn__content > .q-icon'
|
||||
).click();
|
||||
cy.get('.q-gutter-x-sm > .q-btn > .q-btn__content > .q-icon').click();
|
||||
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
|
||||
cy.selectOption(
|
||||
'.q-virtual-scroll__content > :nth-child(2) > :nth-child(1)',
|
||||
'#15'
|
||||
);
|
||||
cy.get('.q-virtual-scroll__content > :nth-child(2) > :nth-child(3)').type('1');
|
||||
cy.get('.q-virtual-scroll__content > :nth-child(2) > :nth-child(4)').type('2');
|
||||
cy.selectOption(
|
||||
'.q-virtual-scroll__content > :nth-child(2) > :nth-child(8)',
|
||||
'Warehouse One'
|
||||
);
|
||||
cy.get('.q-notification__message').should('have.text', 'Data saved');
|
||||
|
||||
cy.get(
|
||||
'.q-virtual-scroll__content > :nth-child(2) > .text-right > .q-btn > .q-btn__content > .q-icon'
|
||||
).click();
|
||||
cy.get(
|
||||
'.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
|
||||
).click();
|
||||
cy.get('.q-notification__message').should('have.text', 'Data saved');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue