Fee CN/DN

This commit is contained in:
2026-06-17 00:08:52 +02:00
parent ee1cb3e7fb
commit a8102d513f
5 changed files with 38 additions and 8 deletions

View File

@@ -1017,6 +1017,9 @@ class Purchase(
logger.info("PROCESS_INVOICE:%s",action)
invoice = purchase.create_invoice(lots,action)
if not invoice:
logger.info(
"PROCESS_INVOICE_NO_INVOICE: purchase=%s action=%s",
getattr(purchase, 'id', None), action)
continue
if action == 'prov':
invoice.reference = 'Provisional'
@@ -1028,6 +1031,7 @@ class Purchase(
if invoices:
cls._save_invoice(invoices,prepayment)
return invoices
@classmethod
def _save_invoice(cls, invoices,prepayment=None):

View File

@@ -107,8 +107,9 @@ class Fee(ModelSQL,ModelView):
('invoiced', 'Invoiced'),
], string='State', readonly=True)
fee_landed_cost = fields.Function(fields.Boolean("Inventory"),'get_landed_status')
inv = fields.Function(fields.Many2One('account.invoice',"Invoice"),'get_invoice')
fee_landed_cost = fields.Function(fields.Boolean("Inventory"),'get_landed_status')
inv = fields.Function(fields.Many2One('account.invoice',"Invoice"),'get_invoice')
dn_cn = fields.Many2One('account.invoice', "DN/CN", readonly=True)
weight_type = fields.Selection([
('net', 'Net'),
@@ -371,6 +372,7 @@ class Fee(ModelSQL,ModelView):
Warning = Pool().get('res.user.warning')
fees_to_invoice = []
for fee in fees:
was_invoiced = fee.state == 'invoiced'
if fee.state == 'invoiced':
warning_name = Warning.format(
"Fee already invoiced", [fee])
@@ -385,7 +387,28 @@ class Fee(ModelSQL,ModelView):
if fee.purchase:
fl = FeeLots.search([('fee','=',fee.id)])
logger.info("PROCESS_FROM_FEE:%s",fl)
Purchase._process_invoice([fee.purchase],[e.lot for e in fl],'service')
fee.adjust_purchase_values()
invoices = Purchase._process_invoice(
[fee.purchase], [e.lot for e in fl], 'service')
invoice = invoices.get(fee.purchase) if invoices else None
logger.info(
"PROCESS_FROM_FEE_RESULT: fee=%s purchase=%s invoice=%s "
"was_invoiced=%s",
getattr(fee, 'id', None), getattr(fee.purchase, 'id', None),
getattr(invoice, 'id', None), was_invoiced)
if not invoice:
if was_invoiced:
raise UserError(
"No debit note or credit note was created for "
"fee %s. The current fee values may be identical "
"to the last invoiced values." % getattr(
fee, 'id', None))
raise UserError(
"No invoice was created for fee %s. Please check "
"that the fee has linked lots and invoiceable values."
% getattr(fee, 'id', None))
if was_invoiced:
cls.write([fee], {'dn_cn': invoice.id})
fees_to_invoice.append(fee)
else:
raise UserError(
@@ -434,9 +457,9 @@ class Fee(ModelSQL,ModelView):
('quantity', '>', 0),
('invoice.state', '!=', 'cancelled'),
], order=[
('invoice.invoice_date', 'DESC'),
('invoice.id', 'DESC'),
('id', 'DESC'),
('invoice.invoice_date', 'ASC'),
('invoice.id', 'ASC'),
('id', 'ASC'),
], limit=1)
if invoice_lines:
return invoice_lines[0].invoice
@@ -450,8 +473,7 @@ class Fee(ModelSQL,ModelView):
invoices,
key=lambda invoice: (
invoice.invoice_date or datetime.date.min,
invoice.id or 0),
reverse=True)[0]
invoice.id or 0))[0]
def get_landed_status(self,name):
if self.product:

View File

@@ -17,6 +17,8 @@
<field name="linked_unit"/>
<label name="linked_price"/>
<field name="linked_price"/>
<label name="dn_cn"/>
<field name="dn_cn"/>
<!-- <label name="supplier"/>
<field name="supplier"/>
<label name="p_r"/>

View File

@@ -19,6 +19,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit_shipment"/>
<!-- <field name="purchase"/> -->
<field name="inv"/>
<field name="dn_cn"/>
<field name="state"/>
<button string="" name="invoice" width="120"/>
</tree>

View File

@@ -18,6 +18,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="qt_state"/>
<!-- <field name="purchase"/> -->
<field name="inv"/>
<field name="dn_cn"/>
<field name="state"/>
<button string="" name="invoice" width="120"/>
</tree>