fix(adopt): 采纳时优先按来源单位工料机行取数,避免同码串规格(PC40→PC32)
This commit is contained in:
@@ -946,7 +946,23 @@ def _adopt_summary_rows(sc, hc, sid, uw_id, src_bill_id):
|
|||||||
for code in codes:
|
for code in codes:
|
||||||
if code in _skip:
|
if code in _skip:
|
||||||
continue
|
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=?)
|
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()
|
AND Number=? ORDER BY id DESC LIMIT 1""", (src_bill_id, code)).fetchone()
|
||||||
if lm is None:
|
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)
|
sc.execute("""INSERT INTO s_norm_res(norm_id, res_code, qty, express, x_ntp, x_taxp)
|
||||||
VALUES(?,?,?,?,?,?)""",
|
VALUES(?,?,?,?,?,?)""",
|
||||||
(cur.lastrowid, rr["res_code"], rr["qty"], rr["express"], a[0], a[1]))
|
(cur.lastrowid, rr["res_code"], rr["qty"], rr["express"], a[0], a[1]))
|
||||||
# 决策 322 差额法(采纳落库尾):**同项目采纳**才按“目标单位现价”算差;
|
# 决策 322 差额法(采纳落库尾):**逐条定额**按目标单位现价重算——
|
||||||
# 跨项目采纳(2026-11-14 主人拍板 B)现合计取来源批次价 → 差额=0,
|
# 新价 = 源价 + Σ((目标现价 − 源价) × 含量);口径 cos/cos4 除税(x_price_basis)。
|
||||||
# 定额价=来源定额价(insert 已写锚价),目标改价后再由 322 级联增量反映。
|
_cur_total = 0.0
|
||||||
if src_self:
|
for rr in _norm_res(nn["id"]):
|
||||||
_cur_total = 0.0
|
_mc = code_map.get(rr["res_code"], rr["res_code"]) if not src_self else rr["res_code"]
|
||||||
for rr in _norm_res(nn["id"]):
|
_np2, _tp2 = _lme_ntp_of(sc, sid, sb["uw_id"], _mc)
|
||||||
_np2, _tp2 = _lme_ntp_of(sc, sid, sb["uw_id"], rr["res_code"])
|
_pr2 = _tp2 if _vb == "taxp" else _np2
|
||||||
_pr2 = _tp2 if _vb == "taxp" else _np2
|
if _pr2 is None:
|
||||||
if _pr2 is None:
|
_pr2 = _np2 if _np2 is not None else _tp2
|
||||||
_pr2 = _np2 if _np2 is not None else _tp2
|
_cur_total += float(rr["qty"] or 0) * float(_pr2 or 0)
|
||||||
_cur_total += float(rr["qty"] or 0) * float(_pr2 or 0)
|
if _va is not None and _vt is not None:
|
||||||
if _va is not None and _vt is not None:
|
sc.execute("UPDATE s_norms SET Price=?, x_lme_total=? WHERE id=?",
|
||||||
sc.execute("UPDATE s_norms SET Price=?, x_lme_total=? WHERE id=?",
|
(_r2(float(_va) + (_cur_total - float(_vt))), _cur_total, cur.lastrowid))
|
||||||
(_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
|
_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):
|
if _cf0 in (None, 0) and bb["Quantity"] not in (None, 0):
|
||||||
try:
|
_cf0 = float(nn["Quantity"] or 0) / float(bb["Quantity"])
|
||||||
_uf = unit_factor(nn["Unit"])
|
|
||||||
except Exception:
|
|
||||||
_uf = 1.0
|
|
||||||
_cf0 = float(nn["Quantity"] or 0) * float(_uf or 1.0) / float(bb["Quantity"])
|
|
||||||
_adopted.append((cur.lastrowid, float(_cf0 or 0)))
|
_adopted.append((cur.lastrowid, float(_cf0 or 0)))
|
||||||
# 决策 333(2026-11-14 斗门莲洲实证):清单价=Σ(定额单位含量×定额价),定额价=
|
# 决策 333(2026-11-14 斗门莲洲实证):清单价=Σ(定额单位含量×定额价),定额价=
|
||||||
# 322 差额法价(上段已写);合价=清单价×清单量,量空/0→价、合价留空。
|
# 322 差额法价(上段已写);合价=清单价×清单量,量空/0→价、合价留空。
|
||||||
|
|||||||
Reference in New Issue
Block a user