diff --git a/.changeset/modern-chicken-compare.md b/.changeset/modern-chicken-compare.md new file mode 100644 index 000000000..9ff11148d --- /dev/null +++ b/.changeset/modern-chicken-compare.md @@ -0,0 +1,5 @@ +--- +"@hera/plugin-rental": patch +--- + +修改合同方案租赁明细表的添加校验 diff --git a/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts b/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts index 4a0d5d451..5c9cb9edd 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/services/contract-rule-service.ts @@ -71,14 +71,14 @@ export class ContractRuleService { if (!options.values?.contract_plan && !options.values?.products) return; const plan = await this.db.getRepository('contract_plans').findOne({ where: { - id: options.values.contract_plan.id, + id: options.values?.contract_plan?.id || options.values?.contract_plan_id, }, appends: ['lease_items', 'lease_items.products'], }); const add = options.values.products; - const productData = plan.lease_items.map((item) => item.products).flat(); + const productData = plan.lease_items.filter(item => item.id !== options.values.id && item.products.length === add.length).map((item) => item.products).flat() productData.forEach((item) => { - const isHas = add.find((p) => p.raw_category_id === item.raw_category_id); + const isHas = add.find((p) => (p.id < 99999 && (p.id === item.id || (item.id > 99999 && p.raw_category_id === item.raw_category_id))) || (p.id > 99999 && p.raw_category_id === item.raw_category_id)); if (isHas) { throw new Error('方案中存在此产品'); }