main #7
@@ -174,7 +174,7 @@ class Fee(ModelSQL,ModelView):
|
|||||||
return round(self.price / self.quantity,4)
|
return round(self.price / self.quantity,4)
|
||||||
elif self.mode == 'perqt':
|
elif self.mode == 'perqt':
|
||||||
return self.price
|
return self.price
|
||||||
elif self.mode == 'pprice':
|
elif self.mode == 'pprice' or self.mode == 'pcost':
|
||||||
if self.line and self.price:
|
if self.line and self.price:
|
||||||
return round(self.price * Decimal(self.line.unit_price) / 100,4)
|
return round(self.price * Decimal(self.line.unit_price) / 100,4)
|
||||||
if self.sale_line and self.price:
|
if self.sale_line and self.price:
|
||||||
@@ -297,46 +297,48 @@ class Fee(ModelSQL,ModelView):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, vlist):
|
def create(cls, vlist):
|
||||||
vlist = [x.copy() for x in vlist]
|
vlist = [x.copy() for x in vlist]
|
||||||
records = super(Fee, cls).create(vlist)
|
fees = super(Fee, cls).create(vlist)
|
||||||
qt_sh = Decimal(0)
|
qt_sh = Decimal(0)
|
||||||
qt_line = Decimal(0)
|
qt_line = Decimal(0)
|
||||||
unit = None
|
unit = None
|
||||||
for record in records:
|
for fee in fees:
|
||||||
FeeLots = Pool().get('fee.lots')
|
FeeLots = Pool().get('fee.lots')
|
||||||
Lots = Pool().get('lot.lot')
|
Lots = Pool().get('lot.lot')
|
||||||
LotQt = Pool().get('lot.qt')
|
LotQt = Pool().get('lot.qt')
|
||||||
if record.line:
|
if fee.line:
|
||||||
for l in record.line.lots:
|
for l in fee.line.lots:
|
||||||
#if l.lot_type == 'physic':
|
#if l.lot_type == 'physic':
|
||||||
fl = FeeLots()
|
fl = FeeLots()
|
||||||
fl.fee = record.id
|
fl.fee = fee.id
|
||||||
fl.lot = l.id
|
fl.lot = l.id
|
||||||
fl.line = l.line.id
|
fl.line = l.line.id
|
||||||
FeeLots.save([fl])
|
FeeLots.save([fl])
|
||||||
qt_line += l.get_current_quantity_converted()
|
qt_line += l.get_current_quantity_converted()
|
||||||
unit = l.line.unit
|
unit = l.line.unit
|
||||||
if record.sale_line:
|
if fee.sale_line:
|
||||||
for l in record.sale_line.lots:
|
for l in fee.sale_line.lots:
|
||||||
#if l.lot_type == 'physic':
|
#if l.lot_type == 'physic':
|
||||||
fl = FeeLots()
|
fl = FeeLots()
|
||||||
fl.fee = record.id
|
fl.fee = fee.id
|
||||||
fl.lot = l.id
|
fl.lot = l.id
|
||||||
fl.sale_line = l.sale_line.id
|
fl.sale_line = l.sale_line.id
|
||||||
FeeLots.save([fl])
|
FeeLots.save([fl])
|
||||||
if record.shipment_in:
|
qt_line += l.get_current_quantity_converted()
|
||||||
if record.shipment_in.state == 'draft'or record.shipment_in.state == 'started':
|
unit = l.line.unit
|
||||||
lots = Lots.search(['lot_shipment_in','=',record.shipment_in.id])
|
if fee.shipment_in:
|
||||||
|
if fee.shipment_in.state == 'draft'or fee.shipment_in.state == 'started':
|
||||||
|
lots = Lots.search(['lot_shipment_in','=',fee.shipment_in.id])
|
||||||
if lots:
|
if lots:
|
||||||
for l in lots:
|
for l in lots:
|
||||||
#if l.lot_type == 'physic':
|
#if l.lot_type == 'physic':
|
||||||
fl = FeeLots()
|
fl = FeeLots()
|
||||||
fl.fee = record.id
|
fl.fee = fee.id
|
||||||
fl.lot = l.id
|
fl.lot = l.id
|
||||||
FeeLots.save([fl])
|
FeeLots.save([fl])
|
||||||
qt_sh += l.get_current_quantity_converted()
|
qt_sh += l.get_current_quantity_converted()
|
||||||
unit = l.line.unit
|
unit = l.line.unit
|
||||||
else:
|
else:
|
||||||
lqts = LotQt.search(['lot_shipment_in','=',record.shipment_in.id])
|
lqts = LotQt.search(['lot_shipment_in','=',fee.shipment_in.id])
|
||||||
if lqts:
|
if lqts:
|
||||||
for l in lqts:
|
for l in lqts:
|
||||||
qt_sh += l.lot_p.get_current_quantity_converted()
|
qt_sh += l.lot_p.get_current_quantity_converted()
|
||||||
@@ -344,45 +346,45 @@ class Fee(ModelSQL,ModelView):
|
|||||||
else:
|
else:
|
||||||
raise UserError("You cannot add fee on received shipment!")
|
raise UserError("You cannot add fee on received shipment!")
|
||||||
|
|
||||||
type = record.type
|
type = fee.type
|
||||||
if type == 'ordered':
|
if type == 'ordered':
|
||||||
Purchase = Pool().get('purchase.purchase')
|
Purchase = Pool().get('purchase.purchase')
|
||||||
PurchaseLine = Pool().get('purchase.line')
|
PurchaseLine = Pool().get('purchase.line')
|
||||||
pl = PurchaseLine()
|
pl = PurchaseLine()
|
||||||
pl.product = record.product
|
pl.product = fee.product
|
||||||
if record.line:
|
if fee.line or fee.sale_line:
|
||||||
pl.quantity = round(qt_line,5)
|
pl.quantity = round(qt_line,5)
|
||||||
if record.shipment_in:
|
if fee.shipment_in:
|
||||||
pl.quantity = round(qt_sh,5)
|
pl.quantity = round(qt_sh,5)
|
||||||
logger.info("CREATE_PURHCASE_FOR_FEE_QT:%s",pl.quantity)
|
logger.info("CREATE_PURHCASE_FOR_FEE_QT:%s",pl.quantity)
|
||||||
pl.unit = unit
|
pl.unit = unit
|
||||||
pl.fee_ = record.id
|
pl.fee_ = fee.id
|
||||||
if record.price:
|
if fee.price:
|
||||||
pl.unit_price = round(Decimal(record.price),4)
|
pl.unit_price = round(Decimal(fee.get_price_per_qt()),4)
|
||||||
p = Purchase()
|
p = Purchase()
|
||||||
p.lines = [pl]
|
p.lines = [pl]
|
||||||
p.party = record.supplier
|
p.party = fee.supplier
|
||||||
if p.party.addresses:
|
if p.party.addresses:
|
||||||
p.invoice_address = p.party.addresses[0]
|
p.invoice_address = p.party.addresses[0]
|
||||||
p.currency = record.currency
|
p.currency = fee.currency
|
||||||
p.line_type = 'service'
|
p.line_type = 'service'
|
||||||
Purchase.save([p])
|
Purchase.save([p])
|
||||||
#if reception of moves done we need to generate accrual for fee
|
#if reception of moves done we need to generate accrual for fee
|
||||||
StockMove = Pool().get('stock.move')
|
if not fee.sale_line:
|
||||||
feelots = FeeLots.search(['fee','=',record.id])
|
feelots = FeeLots.search(['fee','=',fee.id])
|
||||||
for fl in feelots:
|
for fl in feelots:
|
||||||
move = fl.lot.get_received_move()
|
move = fl.lot.get_received_move()
|
||||||
if move:
|
if move:
|
||||||
Warning = Pool().get('res.user.warning')
|
Warning = Pool().get('res.user.warning')
|
||||||
warning_name = Warning.format("Lot ever received", [])
|
warning_name = Warning.format("Lot ever received", [])
|
||||||
if Warning.check(warning_name):
|
if Warning.check(warning_name):
|
||||||
raise UserWarning(warning_name,
|
raise UserWarning(warning_name,
|
||||||
"By clicking yes, an accrual for this fee will be created")
|
"By clicking yes, an accrual for this fee will be created")
|
||||||
AccountMove = Pool().get('account.move')
|
AccountMove = Pool().get('account.move')
|
||||||
account_move = move._get_account_stock_move_fee(record)
|
account_move = move._get_account_stock_move_fee(fee)
|
||||||
AccountMove.save([account_move])
|
AccountMove.save([account_move])
|
||||||
|
|
||||||
return records
|
return fees
|
||||||
|
|
||||||
class FeeLots(ModelSQL,ModelView):
|
class FeeLots(ModelSQL,ModelView):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user