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