This commit is contained in:
2026-01-27 17:26:42 +01:00
parent 71a58814b4
commit 408c5d82e4

View File

@@ -261,88 +261,82 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
logger.info("DECLARATION_KEY:%s",dec_key) logger.info("DECLARATION_KEY:%s",dec_key)
declaration = SaleLine.search(['note','=',dec_key]) declaration = SaleLine.search(['note','=',dec_key])
if declaration: if declaration:
with Transaction().new_transaction() as trans1: continue
sale_line = declaration[0] sale_line = declaration[0]
logger.info("WITH_DEC:%s",sale_line) logger.info("WITH_DEC:%s",sale_line)
vlot = sale_line.lots[0] vlot = sale_line.lots[0]
lqt = LotQt.search([('lot_s','=',vlot.id)]) lqt = LotQt.search([('lot_s','=',vlot.id)])
if lqt and lqt[0].lot_p: if lqt and lqt[0].lot_p:
logger.info("VLOT_P:%s",lqt[0].lot_p) logger.info("VLOT_P:%s",lqt[0].lot_p)
lqt[0].lot_p.updateVirtualPart(round(lot_net_weight,2),sh[0],lqt[0].lot_s) lqt[0].lot_p.updateVirtualPart(round(lot_net_weight,2),sh[0],lqt[0].lot_s)
trans1.commit()
else: else:
sale = Sale() sale = Sale()
sale_line = SaleLine() sale_line = SaleLine()
with Transaction().new_transaction() as trans1: sale.party = Party.getPartyByName(customer,'CLIENT')
sale.party = Party.getPartyByName(customer,'CLIENT') logger.info("SALE_PARTY:%s",sale.party)
logger.info("SALE_PARTY:%s",sale.party) sale.reference = reference
sale.reference = reference sale.company = 6
sale.company = 6 if sale.party.addresses:
if sale.party.addresses: sale.invoice_address = sale.party.addresses[0]
sale.invoice_address = sale.party.addresses[0] sale.shipment_address = sale.party.addresses[0]
sale.shipment_address = sale.party.addresses[0]
if sell_price_currency == 'USC':
if sell_price_currency == 'USC': sale.currency = Currency.get_by_name('USD')
sale.currency = Currency.get_by_name('USD') sale_line.enable_linked_currency = True
sale_line.enable_linked_currency = True sale_line.linked_currency = 1
sale_line.linked_currency = 1 sale_line.linked_unit = Uom.get_by_name(sell_price_unit)
sale_line.linked_unit = Uom.get_by_name(sell_price_unit) sale_line.linked_price = round(sell_price,4)
sale_line.linked_price = round(sell_price,4) sale_line.unit_price = sale_line.get_price_linked_currency()
sale_line.unit_price = sale_line.get_price_linked_currency() else:
else: sale.currency = Currency.get_by_name(sell_price_currency)
sale.currency = Currency.get_by_name(sell_price_currency) sale_line.unit_price = round(sell_price,4)
sale_line.unit_price = round(sell_price,4) sale_line.unit = Uom.get_by_name(sell_price_unit)
sale_line.unit = Uom.get_by_name(sell_price_unit) sale_line.premium = premium
sale_line.premium = premium Sale.save([sale])
Sale.save([sale]) sale_line.sale = sale.id
sale_line.sale = sale.id sale_line.quantity = round(lot_net_weight,2)
sale_line.quantity = round(lot_net_weight,2) sale_line.quantity_theorical = round(lot_net_weight,2)
sale_line.quantity_theorical = round(lot_net_weight,2) sale_line.product = Product.get_by_name('BRAZIL COTTON')
sale_line.product = Product.get_by_name('BRAZIL COTTON') logger.info("PRODUCT:%s",sale_line.product)
logger.info("PRODUCT:%s",sale_line.product) sale_line.unit = Uom.get_by_name(lot_unit)
sale_line.unit = Uom.get_by_name(lot_unit) sale_line.price_type = 'priced'
sale_line.price_type = 'priced' sale_line.created_by_code = False
sale_line.created_by_code = False sale_line.note = dec_key
sale_line.note = dec_key SaleLine.save([sale_line])
SaleLine.save([sale_line])
trans1.commit()
with Transaction().new_transaction() as trans2: ContractStart = Pool().get('contracts.start')
ContractStart = Pool().get('contracts.start') ContractDetail = Pool().get('contract.detail')
ContractDetail = Pool().get('contract.detail') ct = ContractStart()
ct = ContractStart() d = ContractDetail()
d = ContractDetail() ct.type = 'Purchase'
ct.type = 'Purchase' ct.matched = True
ct.matched = True ct.shipment_in = sh[0]
ct.shipment_in = sh[0] ct.lot = sale_line.lots[0]
ct.lot = sale_line.lots[0] ct.product = sale_line.product
ct.product = sale_line.product ct.unit = sale_line.unit
ct.unit = sale_line.unit d.party = Party.getPartyByName('FAIRCOT')
d.party = Party.getPartyByName('FAIRCOT') if sale_line.enable_linked_currency:
if sale_line.enable_linked_currency: d.currency_unit = str(sale_line.linked_currency.id) + '_' + str(sale_line.linked_unit.id)
d.currency_unit = str(sale_line.linked_currency.id) + '_' + str(sale_line.linked_unit.id) else:
else: d.currency_unit = str(sale.currency.id) + '_' + str(sale_line.unit.id)
d.currency_unit = str(sale.currency.id) + '_' + str(sale_line.unit.id) d.quantity = sale_line.quantity
d.quantity = sale_line.quantity d.unit = sale_line.unit
d.unit = sale_line.unit d.price = sale_line.unit_price
d.price = sale_line.unit_price d.price_type = 'priced'
d.price_type = 'priced' d.crop = None
d.crop = None d.tol_min = 0
d.tol_min = 0 d.tol_max = 0
d.tol_max = 0 d.incoterm = None
d.incoterm = None d.reference = str(sale.id)
d.reference = str(sale.id) d.del_period = None
d.del_period = None d.from_del = None
d.from_del = None d.to_del = None
d.to_del = None ct.contracts = [d]
ct.contracts = [d] ContractFactory.create_contracts(
ContractFactory.create_contracts( ct.contracts,
ct.contracts, type_=ct.type,
type_=ct.type, ct=ct,
ct=ct, )
)
trans2.commit()
#Lots creation #Lots creation
# vlot = sale_line.lots[0] # vlot = sale_line.lots[0]