diff --git a/client/cypress/e2e/posting-bills/posting-bills.cy.js b/client/cypress/e2e/posting-bills/posting-bills.cy.js index 3e3ca29aa..888e482ce 100644 --- a/client/cypress/e2e/posting-bills/posting-bills.cy.js +++ b/client/cypress/e2e/posting-bills/posting-bills.cy.js @@ -1,6 +1,7 @@ import job from "../../fixtures/jobs/job-3.json"; import job2 from "../../fixtures/jobs/job-4.json"; import moment from "moment"; +import Dinero from "dinero.js"; const uuid = () => Cypress._.random(0, 1e6); @@ -250,10 +251,17 @@ describe( describe.only( "Validating and calculating bills", { - defaultCommandTimeout: 5000, + defaultCommandTimeout: 10000, }, () => { const today = moment(new Date()).format("YYYY-MM-DD"); + const jobLines = job2.joblines.data.filter( + (line) => line.part_type === "PAS" || line.part_type === "PAE" + ); + const linesTotal = jobLines.reduce( + (prev, line) => prev + line.act_price, + 0 + ); beforeEach(() => { cy.viewport(1280, 720); @@ -282,7 +290,7 @@ describe.only( cy.get('[data-cy="tab-partssublet"]').should("be.visible").click(); }); - it.only("validates auto reconciliation through posting bill", () => { + it("validates auto reconciliation through posting bill", () => { // Find the first row in the parts order cy.get('[data-cy="part-orders-table"]') .find(".ant-table-tbody") @@ -300,7 +308,7 @@ describe.only( cy.get('[data-cy="bill-form-invoice"]').type(uuid()); cy.get("#bill-form-date").click(); - cy.get(`[title="${today}"]`).should("be.visible").click(); + cy.get(`[title="${today}"]`).should("be.visible").click({ force: true }); cy.get('[data-cy="bill-line-table"]').each(($row) => { // get retail amount @@ -338,22 +346,28 @@ describe.only( cy.get("#bill-form-discrepancy").should("have.text", "$0.00"); // Click save - // cy.get('[data-cy="bill-form-save-button"]').click(); + cy.get('[data-cy="bill-form-save-button"]').click(); cy.get("@retailPrice") .invoke("val") .then((val) => { + const discrepancy = linesTotal - Number(val); + cy.get("#retailtotal").should("have.text", `$${val}`); + + cy.get(".discrepancy").each(($statistic) => { + cy.wrap($statistic).should( + "have.text", + Dinero({ + amount: discrepancy, + precision: 0, + }).toFormat() + ); + }); }); - - // TODO get total of discrepancy - - // cy.get(".discrepancy").each(($statistic) => { - // cy.wrap($statistic).should("have.text", "$0.00"); - // }); }); - it("returning item and validating statistics", () => { + it.only("returning item and validating statistics", () => { cy.get('[data-cy="bills-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") @@ -368,20 +382,23 @@ describe.only( cy.get('[data-cy="billline-checkbox"]').check(); cy.get('[data-cy="billline-return-items-ok-button"]').click(); - - cy.get("#order-quantity").type("1", { force: true, multiple: true }); - cy.get('[data-cy="part-order-select-none"]').click({ - multiple: true, - force: true, - }); - cy.get('[data-cy="order-part-submit"]').click({ - multiple: true, - force: true, - }); - - cy.get("#totalReturns").should("have.text", "$83.87"); - cy.get("#calculatedcreditsnotreceived").should("have.text", "$83.87"); - cy.get("#creditsnotreceived").should("have.text", "$83.87"); + cy.get('[data-cy="billline-actual-price"]') + .find(".ant-form-item-control-input-content") + .invoke("text") + .then((value) => { + cy.get("#order-quantity").type("1", { force: true, multiple: true }); + cy.get('[data-cy="part-order-select-none"]').click({ + multiple: true, + force: true, + }); + cy.get('[data-cy="order-part-submit"]').click({ + multiple: true, + force: true, + }); + cy.get("#totalReturns").should("have.text", value); + cy.get("#calculatedcreditsnotreceived").should("have.text", value); + cy.get("#creditsnotreceived").should("have.text", value); + }); }); it("receives credit memo without return part", () => { diff --git a/client/src/components/bill-detail-edit/bill-detail-edit-return.component.jsx b/client/src/components/bill-detail-edit/bill-detail-edit-return.component.jsx index ebd999269..a4b97cea9 100644 --- a/client/src/components/bill-detail-edit/bill-detail-edit-return.component.jsx +++ b/client/src/components/bill-detail-edit/bill-detail-edit-return.component.jsx @@ -153,6 +153,7 @@ export function BillDetailEditReturn({ // label={t("joblines.fields.actual_price")} key={`${index}actual_price`} name={[field.name, "actual_price"]} + data-cy="billline-actual-price" > diff --git a/client/src/components/form-items-formatted/read-only-form-item.component.jsx b/client/src/components/form-items-formatted/read-only-form-item.component.jsx index fd50b9c94..72c85ad41 100644 --- a/client/src/components/form-items-formatted/read-only-form-item.component.jsx +++ b/client/src/components/form-items-formatted/read-only-form-item.component.jsx @@ -5,13 +5,11 @@ const ReadOnlyFormItem = ({ value, type = "text", onChange }, ref) => { if (!value) return null; switch (type) { case "text": - return
{value}
; + return <>{value}; case "currency": - return ( -
{Dinero({ amount: Math.round(value * 100) }).toFormat()}
- ); + return <>{Dinero({ amount: Math.round(value * 100) }).toFormat()}; default: - return
{value}
; + return <>{value}; } }; export default forwardRef(ReadOnlyFormItem); diff --git a/client/src/components/job-bills-total/job-bills-total.component.jsx b/client/src/components/job-bills-total/job-bills-total.component.jsx index 66f809958..89c25e285 100644 --- a/client/src/components/job-bills-total/job-bills-total.component.jsx +++ b/client/src/components/job-bills-total/job-bills-total.component.jsx @@ -84,6 +84,8 @@ export default function JobBillsTotalComponent({ }) ); + console.log(totals.parts.parts.total); + const totalPartsSublet = Dinero(totals.parts.parts.total) .add(Dinero(totals.parts.sublets.total)) .add(Dinero(totals.additional.shipping))