feat(bloco-c): motor fiscal com legal_basis obrigatorio, classificacao NCM, seguranca CEST/IPI e validador GTIN
This commit is contained in:
@@ -72,6 +72,11 @@ def name_candidates(session, description) -> list[KbProduct]:
|
||||
|
||||
|
||||
def upsert_product(session, key: str | None, description, *, brand=None, quantity=None) -> KbProduct:
|
||||
if key:
|
||||
from ..gtin_validator import validate_gtin
|
||||
valid, _ = validate_gtin(key)
|
||||
if not valid:
|
||||
key = None # Regra C.6: GTIN inválido (DV ou prefixo errado) não entra na KB
|
||||
product = find_by_gtin(session, key)
|
||||
if product is None:
|
||||
fp = gtin_fingerprint(key) if key else hashlib.sha256(f"name:{textnorm.fingerprint(description)}".encode()).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user