From f0be141fccaba6bff62f9464e567808032a8a4b3 Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:37:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(adopt):=20=E9=87=87=E7=BA=B3=E6=97=B6?= =?UTF-8?q?=E4=BC=98=E5=85=88=E6=8C=89=E6=9D=A5=E6=BA=90=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E5=B7=A5=E6=96=99=E6=9C=BA=E8=A1=8C=E5=8F=96=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=90=8C=E7=A0=81=E4=B8=B2=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=EF=BC=88PC40=E2=86=92PC32=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CostReview/app/server/adopt_api.py | 51 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/CostReview/app/server/adopt_api.py b/CostReview/app/server/adopt_api.py index e76073b..8105d12 100644 --- a/CostReview/app/server/adopt_api.py +++ b/CostReview/app/server/adopt_api.py @@ -946,7 +946,23 @@ def _adopt_summary_rows(sc, hc, sid, uw_id, src_bill_id): for code in codes: if code in _skip: continue - lm = hc.execute("""SELECT Number, Name, Specification, Unit, Kind, Quantity, TaxRate, NoTaxPrice, TaxPrice + # 2026-11-15 主人定「采纳按源清单当时的定额/工料机原样带」:优先取**来源清单所在单位** + # 的单位工料机行(lme_uw)——lmes/lme_lib 是去重/兜底表,同码异物时会串规格 + # (金宝实测 29060140-0001:lib=PC32、源块/单位行=PC40)。 + lm = None + try: + _suw = hc.execute("SELECT uw_id FROM bills WHERE id=?", (src_bill_id,)).fetchone() + if _suw and _suw["uw_id"] is not None: + lm = hc.execute("""SELECT code AS Number, name AS Name, spec AS Specification, + unit AS Unit, kind AS Kind, qty AS Quantity, + taxrate AS TaxRate, ntp AS NoTaxPrice, taxp AS TaxPrice + FROM lme_uw WHERE batch_id=(SELECT batch_id FROM bills WHERE id=?) + AND uw_id=? AND code=? ORDER BY id LIMIT 1""", + (src_bill_id, _suw["uw_id"], code)).fetchone() + except sqlite3.OperationalError: + lm = None + if lm is None: + lm = hc.execute("""SELECT Number, Name, Specification, Unit, Kind, Quantity, TaxRate, NoTaxPrice, TaxPrice FROM lmes WHERE batch_id=(SELECT batch_id FROM bills WHERE id=?) AND Number=? ORDER BY id DESC LIMIT 1""", (src_bill_id, code)).fetchone() if lm is None: @@ -1574,27 +1590,22 @@ def api_bill_adopt(sc, hc, body): sc.execute("""INSERT INTO s_norm_res(norm_id, res_code, qty, express, x_ntp, x_taxp) VALUES(?,?,?,?,?,?)""", (cur.lastrowid, rr["res_code"], rr["qty"], rr["express"], a[0], a[1])) - # 决策 322 差额法(采纳落库尾):**同项目采纳**才按“目标单位现价”算差; - # 跨项目采纳(2026-11-14 主人拍板 B)现合计取来源批次价 → 差额=0, - # 定额价=来源定额价(insert 已写锚价),目标改价后再由 322 级联增量反映。 - if src_self: - _cur_total = 0.0 - for rr in _norm_res(nn["id"]): - _np2, _tp2 = _lme_ntp_of(sc, sid, sb["uw_id"], rr["res_code"]) - _pr2 = _tp2 if _vb == "taxp" else _np2 - if _pr2 is None: - _pr2 = _np2 if _np2 is not None else _tp2 - _cur_total += float(rr["qty"] or 0) * float(_pr2 or 0) - if _va is not None and _vt is not None: - sc.execute("UPDATE s_norms SET Price=?, x_lme_total=? WHERE id=?", - (_r2(float(_va) + (_cur_total - float(_vt))), _cur_total, cur.lastrowid)) + # 决策 322 差额法(采纳落库尾):**逐条定额**按目标单位现价重算—— + # 新价 = 源价 + Σ((目标现价 − 源价) × 含量);口径 cos/cos4 除税(x_price_basis)。 + _cur_total = 0.0 + for rr in _norm_res(nn["id"]): + _mc = code_map.get(rr["res_code"], rr["res_code"]) if not src_self else rr["res_code"] + _np2, _tp2 = _lme_ntp_of(sc, sid, sb["uw_id"], _mc) + _pr2 = _tp2 if _vb == "taxp" else _np2 + if _pr2 is None: + _pr2 = _np2 if _np2 is not None else _tp2 + _cur_total += float(rr["qty"] or 0) * float(_pr2 or 0) + if _va is not None and _vt is not None: + sc.execute("UPDATE s_norms SET Price=?, x_lme_total=? WHERE id=?", + (_r2(float(_va) + (_cur_total - float(_vt))), _cur_total, cur.lastrowid)) _cf0 = nn["x_qty_coef"] if "x_qty_coef" in nn.keys() else None if _cf0 in (None, 0) and bb["Quantity"] not in (None, 0): - try: - _uf = unit_factor(nn["Unit"]) - except Exception: - _uf = 1.0 - _cf0 = float(nn["Quantity"] or 0) * float(_uf or 1.0) / float(bb["Quantity"]) + _cf0 = float(nn["Quantity"] or 0) / float(bb["Quantity"]) _adopted.append((cur.lastrowid, float(_cf0 or 0))) # 决策 333(2026-11-14 斗门莲洲实证):清单价=Σ(定额单位含量×定额价),定额价= # 322 差额法价(上段已写);合价=清单价×清单量,量空/0→价、合价留空。