feat: Add production and expiration dates to stock move lines and update delivery slip report
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from . import models
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
{
|
{
|
||||||
'name': 'Custom Delivery Slip',
|
'name': 'Custom Delivery Slip',
|
||||||
'version': '19.0.1.0.0',
|
'version': '19.0.1.0.1',
|
||||||
'category': 'Inventory',
|
'category': 'Inventory',
|
||||||
'summary': 'Customize delivery slip with lot number, production date, expiration date',
|
'summary': 'Add production and expiration dates to delivery order labels',
|
||||||
'description': """
|
'description': """
|
||||||
Adds the following fields to delivery slips:
|
Adds production and expiration date labels to delivery orders.
|
||||||
- Lot/Serial number
|
|
||||||
- Production date (today's date)
|
- Production date (today's date)
|
||||||
- Expiration date (6 months from production)
|
- Expiration date (6 months from production)
|
||||||
- Product name
|
|
||||||
""",
|
""",
|
||||||
'depends': ['stock'],
|
'depends': ['stock'],
|
||||||
'data': [
|
'data': [
|
||||||
'views/report_deliveryslip.xml',
|
'views/stock_picking_form.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'application': False,
|
'application': False,
|
||||||
|
|||||||
33
odoo/addons/delivery_slip_custom/models.py
Normal file
33
odoo/addons/delivery_slip_custom/models.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from odoo import models, fields, api
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
|
||||||
|
class StockMoveLine(models.Model):
|
||||||
|
_inherit = 'stock.move.line'
|
||||||
|
|
||||||
|
production_date = fields.Date(
|
||||||
|
string='Production Date',
|
||||||
|
compute='_compute_production_date',
|
||||||
|
store=False,
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
expiration_date = fields.Date(
|
||||||
|
string='Expiration Date',
|
||||||
|
compute='_compute_expiration_date',
|
||||||
|
store=False,
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('move_id.create_date')
|
||||||
|
def _compute_production_date(self):
|
||||||
|
"""Set production date to today or the move's creation date"""
|
||||||
|
for line in self:
|
||||||
|
line.production_date = fields.Date.today()
|
||||||
|
|
||||||
|
@api.depends('move_id.create_date')
|
||||||
|
def _compute_expiration_date(self):
|
||||||
|
"""Set expiration date to 6 months (180 days) from today"""
|
||||||
|
for line in self:
|
||||||
|
line.expiration_date = fields.Date.today() + timedelta(days=180)
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<odoo>
|
|
||||||
<!-- Inherit the delivery slip report template for completed deliveries (state='done') -->
|
|
||||||
<template id="stock_report_delivery_has_serial_move_line_custom" inherit_id="stock.stock_report_delivery_has_serial_move_line">
|
|
||||||
<!-- Add Production Date after lot number -->
|
|
||||||
<xpath expr="//td[@name='move_line_lot']" position="after">
|
|
||||||
<td class="text-end">
|
|
||||||
<span t-esc="datetime.datetime.now().strftime('%Y-%m-%d')"/>
|
|
||||||
</td>
|
|
||||||
</xpath>
|
|
||||||
<!-- Add Expiration Date after Production Date -->
|
|
||||||
<xpath expr="//td[@name='move_line_lot_quantity']" position="before">
|
|
||||||
<td class="text-end">
|
|
||||||
<span t-esc="(datetime.datetime.now() + datetime.timedelta(days=180)).strftime('%Y-%m-%d')"/>
|
|
||||||
</td>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Add column headers for Production and Expiration dates in the main table -->
|
|
||||||
<template id="report_delivery_document_custom" inherit_id="stock.report_delivery_document">
|
|
||||||
<!-- Add headers for completed deliveries table -->
|
|
||||||
<xpath expr="//table[@name='stock_move_line_table']/thead/tr/th[@name='lot_serial']" position="after">
|
|
||||||
<th name="th_production_date" class="text-end">Production Date</th>
|
|
||||||
<th name="th_expiration_date" class="text-end">Expiration Date</th>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</odoo>
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- Add production and expiration date fields to stock move lines -->
|
||||||
|
<record id="view_stock_move_line_tree" model="ir.ui.view">
|
||||||
|
<field name="name">stock.move.line.tree.custom</field>
|
||||||
|
<field name="model">stock.move.line</field>
|
||||||
|
<field name="inherit_id" ref="stock.view_move_line_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="product_id" position="after">
|
||||||
|
<field name="production_date" optional="show"/>
|
||||||
|
<field name="expiration_date" optional="show"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user