Fee CN/DN
This commit is contained in:
@@ -1016,16 +1016,18 @@ class Purchase(
|
||||
for purchase in purchases:
|
||||
logger.info("PROCESS_INVOICE:%s",action)
|
||||
invoice = purchase.create_invoice(lots,action)
|
||||
if not invoice:
|
||||
continue
|
||||
if action == 'prov':
|
||||
invoice.reference = 'Provisional'
|
||||
elif action == 'service':
|
||||
invoice.reference = 'Service'
|
||||
else:
|
||||
invoice.reference = 'Final'
|
||||
if invoice:
|
||||
invoices[purchase] = invoice
|
||||
invoices[purchase] = invoice
|
||||
|
||||
cls._save_invoice(invoices,prepayment)
|
||||
if invoices:
|
||||
cls._save_invoice(invoices,prepayment)
|
||||
|
||||
@classmethod
|
||||
def _save_invoice(cls, invoices,prepayment=None):
|
||||
@@ -1854,6 +1856,85 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
|
||||
def on_change_with_currency(self, name=None):
|
||||
return self.purchase.currency if self.purchase else None
|
||||
|
||||
@staticmethod
|
||||
def _record_id(record):
|
||||
return getattr(record, 'id', record)
|
||||
|
||||
@classmethod
|
||||
def _get_last_fee_invoice_line(cls, fee, lot):
|
||||
fee_id = cls._record_id(fee)
|
||||
lot_id = cls._record_id(lot)
|
||||
if not fee_id or not lot_id:
|
||||
return
|
||||
InvoiceLine = Pool().get('account.invoice.line')
|
||||
lines = InvoiceLine.search([
|
||||
('fee', '=', fee_id),
|
||||
('lot', '=', lot_id),
|
||||
('quantity', '>', 0),
|
||||
('invoice.state', '!=', 'cancelled'),
|
||||
], order=[
|
||||
('invoice.invoice_date', 'DESC'),
|
||||
('invoice.id', 'DESC'),
|
||||
('id', 'DESC'),
|
||||
], limit=1)
|
||||
return lines[0] if lines else None
|
||||
|
||||
@staticmethod
|
||||
def _fee_invoice_line_changed(previous_line, invoice_line):
|
||||
if not previous_line:
|
||||
return True
|
||||
previous_quantity = Decimal(str(previous_line.quantity or 0))
|
||||
quantity = Decimal(str(invoice_line.quantity or 0))
|
||||
previous_price = Decimal(str(previous_line.unit_price or 0))
|
||||
price = Decimal(str(invoice_line.unit_price or 0))
|
||||
return previous_quantity != quantity or previous_price != price
|
||||
|
||||
@classmethod
|
||||
def _get_fee_reversal_invoice_line(cls, previous_line, origin):
|
||||
if not previous_line:
|
||||
return
|
||||
InvoiceLine = Pool().get('account.invoice.line')
|
||||
reversal_line, = InvoiceLine.copy([previous_line], default={
|
||||
'invoice': None,
|
||||
'quantity': -previous_line.quantity,
|
||||
'unit_price': previous_line.unit_price,
|
||||
'party': previous_line.invoice.party,
|
||||
'origin': str(origin),
|
||||
})
|
||||
return reversal_line
|
||||
|
||||
def _get_service_fee_invoice_lines(self, invoice_line, lot):
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee.search(['purchase','=',self.purchase.id])
|
||||
if not fee:
|
||||
return [invoice_line]
|
||||
|
||||
fee = fee[0]
|
||||
invoice_line.fee = fee
|
||||
if fee.mode == 'lumpsum':
|
||||
invoice_line.quantity = 1
|
||||
elif fee.mode == 'ppack':
|
||||
invoice_line.quantity = fee.quantity
|
||||
else:
|
||||
state_id = 0
|
||||
LotQtType = Pool().get('lot.qt.type')
|
||||
lqt = LotQtType.search([('name','=','BL')])
|
||||
if lqt:
|
||||
state_id = lqt[0].id
|
||||
invoice_line.quantity = fee.get_fee_lots_qt(state_id)
|
||||
|
||||
if getattr(fee, 'state', None) != 'invoiced':
|
||||
return [invoice_line]
|
||||
|
||||
previous_line = self._get_last_fee_invoice_line(fee, lot)
|
||||
if not self._fee_invoice_line_changed(previous_line, invoice_line):
|
||||
return []
|
||||
reversal_line = self._get_fee_reversal_invoice_line(
|
||||
previous_line, self)
|
||||
if reversal_line:
|
||||
return [reversal_line, invoice_line]
|
||||
return [invoice_line]
|
||||
|
||||
def get_invoice_line(self,lots=None,action=None):
|
||||
'Return a list of invoice line for purchase line'
|
||||
pool = Pool()
|
||||
@@ -1933,21 +2014,9 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
|
||||
invoice_line.unit_price = self.unit_price
|
||||
invoice_line.product = self.product
|
||||
invoice_line.stock_moves = []
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee.search(['purchase','=',self.purchase.id])
|
||||
if fee:
|
||||
invoice_line.fee = fee[0]
|
||||
if fee[0].mode == 'lumpsum':
|
||||
invoice_line.quantity = 1
|
||||
elif fee[0].mode == 'ppack':
|
||||
invoice_line.quantity = fee[0].quantity
|
||||
else:
|
||||
state_id = 0
|
||||
LotQtType = Pool().get('lot.qt.type')
|
||||
lqt = LotQtType.search([('name','=','BL')])
|
||||
if lqt:
|
||||
state_id = lqt[0].id
|
||||
invoice_line.quantity = fee[0].get_fee_lots_qt(state_id)
|
||||
lines.extend(
|
||||
self._get_service_fee_invoice_lines(invoice_line, l))
|
||||
continue
|
||||
|
||||
lines.append(invoice_line)
|
||||
logger.info("GETINVLINE:%s",self.product.type)
|
||||
|
||||
Reference in New Issue
Block a user