Skip to content

Commit

Permalink
product_expiry_simple: black, isort, etc...
Browse files Browse the repository at this point in the history
Travis: exclude the module because it conflicts with product_expiry
  • Loading branch information
alexis-via committed Nov 26, 2021
1 parent 5dcf4b3 commit e8aaf4c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
env:
global:
- VERSION="14.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0"
# product_expiry_simple conflicts with product_expiry from the official addons
- EXCLUDE=product_expiry_simple
- MQT_DEP=PIP

install:
Expand Down
37 changes: 17 additions & 20 deletions product_expiry_simple/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Product Expiry Simple',
'version': '14.0.1.0.0',
'category': 'Product',
'license': 'AGPL-3',
'summary':
'Simpler and better alternative to the official product_expiry module',
'author': 'Akretion,Jarsa Sistemas,Odoo Community Association (OCA)',
'maintainers': ['alexis-via'],
'website': 'http://github.com/OCA/stock-logistics-workflow',
'depends': [
'stock',
"name": "Product Expiry Simple",
"version": "14.0.1.0.0",
"category": "Product",
"license": "AGPL-3",
"summary": "Simpler and better alternative to the official product_expiry module",
"author": "Akretion,Jarsa Sistemas,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": [
"stock",
],
'excludes': [
'product_expiry'
"excludes": ["product_expiry"],
"data": [
"data/product_removal.xml",
"views/stock_production_lot.xml",
"views/stock_quant.xml",
"views/stock_move_line.xml",
],
'data': [
'data/product_removal.xml',
'views/stock_production_lot.xml',
'views/stock_quant.xml',
'views/stock_move_line.xml',
],
'installable': True,
"installable": True,
}
6 changes: 3 additions & 3 deletions product_expiry_simple/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


class StockMoveLine(models.Model):
_inherit = 'stock.move.line'
_inherit = "stock.move.line"

expiry_date = fields.Date(string='Expiry Date')
expiry_date = fields.Date(string="Expiry Date")

# When you read the code of _create_and_assign_production_lot()
# you need the defects of that method:
Expand All @@ -21,4 +21,4 @@ class StockMoveLine(models.Model):
def _assign_production_lot(self, lot):
super()._assign_production_lot(lot)
if self[0].expiry_date:
self.lot_id.write({'expiry_date': self[0].expiry_date})
self.lot_id.write({"expiry_date": self[0].expiry_date})
14 changes: 7 additions & 7 deletions product_expiry_simple/models/stock_production_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo import _, api, fields, models


class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'
_inherit = "stock.production.lot"

expiry_date = fields.Date(string='Expiry Date')
expired = fields.Boolean(compute='_compute_expired')
expiry_date = fields.Date(string="Expiry Date")
expired = fields.Boolean(compute="_compute_expired")

def _compute_expired(self):
today = fields.Date.context_today(self)
Expand All @@ -20,16 +20,16 @@ def _compute_expired(self):
expired = True
lot.expired = expired

@api.depends('name', 'expiry_date')
@api.depends("name", "expiry_date")
def name_get(self):
res = []
today = fields.Date.context_today(self)
for lot in self:
dname = lot.name
if lot.expiry_date:
if lot.expiry_date < today:
dname = _('[%s Expired] %s') % (lot.expiry_date, dname)
dname = _("[%s Expired] %s") % (lot.expiry_date, dname)
else:
dname = '[%s] %s' % (lot.expiry_date, dname)
dname = "[%s] %s" % (lot.expiry_date, dname)
res.append((lot.id, dname))
return res
10 changes: 5 additions & 5 deletions product_expiry_simple/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


class StockQuant(models.Model):
_inherit = 'stock.quant'
_inherit = "stock.quant"

expiry_date = fields.Date(related='lot_id.expiry_date', store=True)
expired = fields.Boolean(related='lot_id.expired')
expiry_date = fields.Date(related="lot_id.expiry_date", store=True)
expired = fields.Boolean(related="lot_id.expired")

# method copy/pasted from the official product_expiry module
# Copyright Odoo SA
@api.model
def _get_removal_strategy_order(self, removal_strategy):
if removal_strategy == 'fefo':
return 'expiry_date, in_date, id'
if removal_strategy == "fefo":
return "expiry_date, in_date, id"
return super()._get_removal_strategy_order(removal_strategy)
22 changes: 17 additions & 5 deletions product_expiry_simple/views/stock_move_line.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_stock_move_line_operation_tree" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.move.line.tree</field>
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_stock_move_line_operation_tree"/>
<field name="inherit_id" ref="stock.view_stock_move_line_operation_tree" />
<field name="arch" type="xml">
<field name="lot_name" position="after">
<field name="expiry_date" attrs="{'readonly': [('package_level_id', '!=', False), ('parent.picking_type_entire_packs', '=', True)]}" invisible="not context.get('show_lots_text')" groups="stock.group_production_lot"/>
<field
name="expiry_date"
attrs="{'readonly': [('package_level_id', '!=', False), ('parent.picking_type_entire_packs', '=', True)]}"
invisible="not context.get('show_lots_text')"
groups="stock.group_production_lot"
/>
</field>
</field>
</record>
<record id="view_stock_move_line_detailed_operation_tree" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.move.line.tree</field>
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_stock_move_line_detailed_operation_tree"/>
<field
name="inherit_id"
ref="stock.view_stock_move_line_detailed_operation_tree"
/>
<field name="arch" type="xml">
<field name="lot_name" position="after">
<field name="expiry_date" attrs="{'column_invisible': [('parent.show_lots_text', '=', False)], 'invisible': [('lots_visible', '=', False)]}" groups="stock.group_production_lot"/>
<field
name="expiry_date"
attrs="{'column_invisible': [('parent.show_lots_text', '=', False)], 'invisible': [('lots_visible', '=', False)]}"
groups="stock.group_production_lot"
/>
</field>
</field>
</record>
Expand Down
43 changes: 30 additions & 13 deletions product_expiry_simple/views/stock_production_lot.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2017-2021 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
Expand All @@ -8,43 +8,60 @@
<record id="view_production_lot_form" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.production.lot.form</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form"/>
<field name="inherit_id" ref="stock.view_production_lot_form" />
<field name="arch" type="xml">
<field name="ref" position="after">
<field name="expiry_date"/>
<field name="expired" invisible="1"/>
<field name="expiry_date" />
<field name="expired" invisible="1" />
</field>
<xpath expr="//div[hasclass('oe_title')]" position="inside">
<span class="badge badge-danger" attrs="{'invisible': [('expired', '=', False)]}">Expired</span>
<span
class="badge badge-danger"
attrs="{'invisible': [('expired', '=', False)]}"
>Expired</span>
</xpath>
</field>
</record>

<record id="view_production_lot_tree" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.production.lot.tree</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_tree"/>
<field name="inherit_id" ref="stock.view_production_lot_tree" />
<field name="arch" type="xml">
<field name="ref" position="after">
<field name="expiry_date" optional="show"/>
<field name="expiry_date" optional="show" />
</field>
<xpath expr="/tree" position="attributes">
<attribute name="decoration-danger">expiry_date and expiry_date &lt; current_date</attribute>
<attribute
name="decoration-danger"
>expiry_date and expiry_date &lt; current_date</attribute>
</xpath>
</field>
</record>
<record id="search_product_lot_filter" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.production.lot.search</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.search_product_lot_filter"/>
<field name="inherit_id" ref="stock.search_product_lot_filter" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<filter domain="[('expiry_date', '&lt;', context_today().strftime('%Y-%m-%d'))]" name="expired" string="Expired"/>
<filter domain="[('expiry_date', '&gt;=', context_today().strftime('%Y-%m-%d'))]" name="no-expired" string="Not Expired"/>
<separator/>
<filter
domain="[('expiry_date', '&lt;', context_today().strftime('%Y-%m-%d'))]"
name="expired"
string="Expired"
/>
<filter
domain="[('expiry_date', '&gt;=', context_today().strftime('%Y-%m-%d'))]"
name="no-expired"
string="Not Expired"
/>
<separator />
</field>
<filter name="group_by_product" position="after">
<filter context="{'group_by': 'expiry_date:month'}" name="expiry_date_groupby" string="Expiry Date"/>
<filter
context="{'group_by': 'expiry_date:month'}"
name="expiry_date_groupby"
string="Expiry Date"
/>
</filter>
</field>
</record>
Expand Down
52 changes: 37 additions & 15 deletions product_expiry_simple/views/stock_quant.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2017-2021 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
Expand All @@ -8,65 +8,87 @@
<record id="view_stock_quant_form" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.quant.form</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_form"/>
<field name="inherit_id" ref="stock.view_stock_quant_form" />
<field name="arch" type="xml">
<field name="product_id" position="before">
<!-- Cannot use context_today() nor current_date in a form view,
only in a tree/search view.
So I added a computed boolean field 'expired' -->
<field name="expired" invisible="1"/>
<span class="badge badge-danger" attrs="{'invisible': [('expired', '=', False)]}">Expired</span>
<field name="expired" invisible="1" />
<span
class="badge badge-danger"
attrs="{'invisible': [('expired', '=', False)]}"
>Expired</span>
</field>
</field>
</record>

<record id="view_stock_quant_tree" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.quant.tree</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree"/>
<field name="inherit_id" ref="stock.view_stock_quant_tree" />
<field name="arch" type="xml">
<field name="lot_id" position="after">
<!-- We show expiry_date in tree view in order to do an "order by" on this column via the interface
But the information is already in the lot_id column via name_get() -->
<field name="expiry_date" optional="hide"/>
<field name="expiry_date" optional="hide" />
</field>
<!-- I prefer to continue to use the full line in red
instead of using widget="badge" decoration-danger=""
on the field expiry_date. That way, we can keep the field
expiry_date hidden by default, which avoids the double info -->
<xpath expr="/tree" position="attributes">
<attribute name="decoration-danger">expiry_date and expiry_date &lt; current_date</attribute>
<attribute
name="decoration-danger"
>expiry_date and expiry_date &lt; current_date</attribute>
</xpath>
</field>
</record>
<record id="view_stock_quant_tree_editable" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.quant.tree.editable</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_editable"/>
<field name="inherit_id" ref="stock.view_stock_quant_tree_editable" />
<field name="arch" type="xml">
<field name="lot_id" position="after">
<!-- We show expiry_date in tree view in order to do an "order by" on this column via the interface
But the information is already in the lot_id column via name_get() -->
<field name="expiry_date" optional="hide"/>
<field name="expiry_date" optional="hide" />
</field>
<xpath expr="/tree" position="attributes">
<attribute name="decoration-danger">expiry_date and expiry_date &lt; current_date</attribute>
<attribute
name="decoration-danger"
>expiry_date and expiry_date &lt; current_date</attribute>
</xpath>
</field>
</record>

<record id="quant_search_view" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.quant.search</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.quant_search_view"/>
<field name="inherit_id" ref="stock.quant_search_view" />
<field name="arch" type="xml">
<filter name="reserved" position="after">
<separator/>
<filter domain="[('expiry_date', '&lt;', context_today().strftime('%Y-%m-%d'))]" groups="stock.group_production_lot" name="expired" string="Expired"/>
<filter domain="[('expiry_date', '&gt;=', context_today().strftime('%Y-%m-%d'))]" groups="stock.group_production_lot" name="no-expired" string="Not Expired"/>
<separator />
<filter
domain="[('expiry_date', '&lt;', context_today().strftime('%Y-%m-%d'))]"
groups="stock.group_production_lot"
name="expired"
string="Expired"
/>
<filter
domain="[('expiry_date', '&gt;=', context_today().strftime('%Y-%m-%d'))]"
groups="stock.group_production_lot"
name="no-expired"
string="Not Expired"
/>
</filter>
<filter context="{'group_by': 'lot_id'}" position="after">
<filter context="{'group_by': 'expiry_date:month'}" groups="stock.group_production_lot" name="expiry_date_groupby" string="Expiry Date"/>
<filter
context="{'group_by': 'expiry_date:month'}"
groups="stock.group_production_lot"
name="expiry_date_groupby"
string="Expiry Date"
/>
</filter>
</field>
</record>
Expand Down
6 changes: 6 additions & 0 deletions setup/product_expiry_simple/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit e8aaf4c

Please sign in to comment.