26.01.26
This commit is contained in:
@@ -4,10 +4,12 @@ from trytond.pyson import Eval
|
||||
from trytond.wizard import Button
|
||||
from trytond.transaction import Transaction
|
||||
from sql import Table
|
||||
from decimal import getcontext, Decimal, ROUND_HALF_UP
|
||||
import requests
|
||||
import io
|
||||
import logging
|
||||
import json
|
||||
from trytond.modules.purchase_trade.service import ContractFactory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -218,22 +220,123 @@ class AutomationDocument(ModelSQL, ModelView, Workflow):
|
||||
t.CUSTOMER,
|
||||
t.SELL_PRICE_CURRENCY,
|
||||
t.SELL_PRICE_UNIT,
|
||||
t.SELL_PRICE,
|
||||
t.SALE_INVOICE,
|
||||
t.SELL_INV_AMOUNT,
|
||||
t.SALE_INVOICE_DATE,
|
||||
t.SELL_PREMIUM,
|
||||
t.SALE_CONTRACT,
|
||||
t.DECLARATION_KEY,
|
||||
where=(t.BOOKING_NUMBER == sh[0].bl_number)
|
||||
))
|
||||
|
||||
rows = cursor.fetchall()
|
||||
if rows:
|
||||
#Purchase & Sale creation
|
||||
Purchase = Pool().get('purchase.purchase')
|
||||
PurchaseLine = Pool().get('purchase.line')
|
||||
for row in rows:
|
||||
#Purchase & Sale creation
|
||||
LotQt = Pool().get('lot.qt')
|
||||
LotAdd = Pool().get('lot.add.line')
|
||||
Currency = Pool().get('currency.currency')
|
||||
Product = Pool().get('product.product')
|
||||
Party = Pool().get('party.party')
|
||||
Uom = Pool().get('product.uom')
|
||||
Sale = Pool().get('sale.sale')
|
||||
SaleLine = Pool().get('sale.line')
|
||||
|
||||
dec_key = str(rows[0][16]).strip()
|
||||
lot_unit = str(rows[0][5]).strip().lower()
|
||||
product = str(rows[0][6]).strip().upper()
|
||||
lot_net_weight = Decimal(rows[0][4])
|
||||
lot_gross_weight = Decimal(rows[0][3])
|
||||
lot_bales = int(rows[0][2])
|
||||
lot_number = rows[0][1]
|
||||
customer = str(rows[0][7]).strip().upper()
|
||||
sell_price_currency = str(rows[0][8]).strip().upper()
|
||||
sell_price_unit = str(rows[0][9]).strip().lower()
|
||||
sell_price = Decimal(rows[0][10])
|
||||
premium = Decimal(rows[0][14])
|
||||
reference = Decimal(rows[0][15])
|
||||
|
||||
declaration = SaleLine.search(['note','=',dec_key])
|
||||
if declaration:
|
||||
sale_line = declaration[0]
|
||||
logger.info("WITH_DEC:%s",sale_line)
|
||||
vlot = sale_line.lots[0]
|
||||
lqt = LotQt.search([('lot_s','=',vlot.id)])
|
||||
lqt.lot_p.updateVirtualPart(lot_net_weight,sh,lqt.lot_s)
|
||||
logger.info("WITH_DEC_LOT_NET:%s",lot_net_weight)
|
||||
else:
|
||||
sale = Sale()
|
||||
sale_line = SaleLine()
|
||||
sale.party = Party.getPartyByName(customer)
|
||||
sale.reference = reference
|
||||
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 = sell_price
|
||||
sale_line.unit_price = sale_line.get_price_linked_currency()
|
||||
else:
|
||||
sale.currency = Currency.get_by_name(sell_price_currency)
|
||||
sale_line.unit_price = sell_price
|
||||
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 = lot_net_weight
|
||||
sale_line.quantity_theorical = lot_net_weight
|
||||
sale_line.product = Product.get_by_name('BRAZIL COTTON')
|
||||
sale_line.unit = Uom.get_id_by_name(lot_unit)
|
||||
sale_line.price_type = 'priced'
|
||||
sale_line.created_by_code = False
|
||||
sale_line.note = dec_key
|
||||
SaleLine.save([sale_line])
|
||||
|
||||
ContractStart = Pool().get('contracts.start')
|
||||
ContractDetail = Pool().get('contract.detail')
|
||||
ct = ContractStart()
|
||||
d = ContractDetail()
|
||||
ct.type = 'Purchase'
|
||||
ct.matched = True
|
||||
ct.shipment_in = sh
|
||||
ct.lot = sale_line.lots[0]
|
||||
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'
|
||||
ct.contracts = [d]
|
||||
ContractFactory.create_contracts(
|
||||
ct.contracts,
|
||||
type_=ct.type,
|
||||
ct=ct,
|
||||
)
|
||||
|
||||
#Lots creation
|
||||
pass
|
||||
vlot = sale_line.lots[0]
|
||||
lqt = LotQt.search([('lot_s','=',vlot.id)])
|
||||
if lqt and vlot.lot_quantity > 0:
|
||||
lqt = lqt[0]
|
||||
l = LotAdd()
|
||||
l.lot_qt = lot_bales
|
||||
l.lot_unit = Uom.get_by_name('bale')
|
||||
l.lot_unit_line = lot_unit
|
||||
l.lot_quantity = lot_net_weight
|
||||
l.lot_gross_quantity = lot_gross_weight
|
||||
l.lot_premium = premium
|
||||
LotQt.add_physical_lots(lqt,[l])
|
||||
|
||||
|
||||
|
||||
# if cls.rule_set.ocr_required:[]
|
||||
# cls.run_ocr([doc])
|
||||
# if cls.rule_set.structure_required and doc.state != "error":
|
||||
|
||||
@@ -137,6 +137,13 @@ class Currency(
|
||||
closer = date
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def get_by_name(cls, name):
|
||||
currencies = cls.search([('symbol', '=', name)], limit=1)
|
||||
if not currencies:
|
||||
return None
|
||||
return currencies[0]
|
||||
|
||||
@staticmethod
|
||||
def _get_rate(currencies, tdate=None):
|
||||
'''
|
||||
|
||||
@@ -609,6 +609,26 @@ class Product(
|
||||
('template.code', operator, code_value, *extra),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_by_name(cls, name, type_='goods'):
|
||||
pool = Pool()
|
||||
Template = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
templates = Template.search([('name', '=', name)], limit=1)
|
||||
if templates:
|
||||
return templates[0].products[0]
|
||||
|
||||
unit_uom, = Uom.search([('name', '=', 'Mt')], limit=1)
|
||||
|
||||
template, = Template.create([{
|
||||
'name': name,
|
||||
'type': type_,
|
||||
'default_uom': unit_uom.id,
|
||||
'cost_price_method': 'fixed',
|
||||
}])
|
||||
return template.products[0]
|
||||
|
||||
@staticmethod
|
||||
def get_price_uom(products, name):
|
||||
Uom = Pool().get('product.uom')
|
||||
|
||||
@@ -92,6 +92,13 @@ class Uom(SymbolMixin, DigitsMixin, DeactivableMixin, ModelSQL, ModelView):
|
||||
def default_digits():
|
||||
return 2
|
||||
|
||||
@classmethod
|
||||
def get_by_name(cls, name):
|
||||
uom = cls.search([('symbol', '=', name)], limit=1)
|
||||
if not uom:
|
||||
return None
|
||||
return uom[0]
|
||||
|
||||
@fields.depends('factor')
|
||||
def on_change_factor(self):
|
||||
if (self.factor or 0.0) == 0.0:
|
||||
|
||||
@@ -3144,10 +3144,10 @@ class CreateContracts(Wizard):
|
||||
|
||||
def transition_creating(self):
|
||||
ContractFactory.create_contracts(
|
||||
self.ct.contracts,
|
||||
type_=self.ct.type,
|
||||
ct=self.ct,
|
||||
)
|
||||
self.ct.contracts,
|
||||
type_=self.ct.type,
|
||||
ct=self.ct,
|
||||
)
|
||||
# SaleLine = Pool().get('sale.line')
|
||||
# Sale = Pool().get('sale.sale')
|
||||
# PurchaseLine = Pool().get('purchase.line')
|
||||
|
||||
Reference in New Issue
Block a user