Skip to content
Extraits de code Groupes Projets
Valider aed7c60f rédigé par Rémi - Le Filament's avatar Rémi - Le Filament
Parcourir les fichiers

Merge branch 'dev' into '14.0'

Mise à jour calcul dates des lots

See merge request !1
parents 2561df07 0541fa00
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!1Mise à jour calcul dates des lots
...@@ -12,10 +12,8 @@ ...@@ -12,10 +12,8 @@
'fumoc_partner', 'fumoc_partner',
], ],
'data': [ 'data': [
"security/ir.model.access.csv",
# datas # datas
# views # views
'views/fumoc_lot_prefix_dlc.xml',
'views/product_views.xml', 'views/product_views.xml',
'views/res_config_settings.xml', 'views/res_config_settings.xml',
'views/sale_order.xml', 'views/sale_order.xml',
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_move from . import account_move
from . import fumoc_lot_prefix_dlc
from . import product from . import product
from . import res_company from . import res_company
from . import res_config_settings from . import res_config_settings
......
# Copyright 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class FumocLotPrefixDLC(models.Model):
_name = 'fumoc.lot.prefix.dlc'
_description = 'Correspondance préfix des lots et DLC'
name = fields.Char('Descrition')
prefix = fields.Char('Préfixe', required=True)
dlc = fields.Integer('DLC')
_sql_constraints = [
('unique_prefix', 'unique(prefix)',
'Le préfixe doit être unique')
]
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import datetime import datetime
import re import re
from odoo import models, api from odoo import models, fields, api
from odoo.exceptions import UserError from odoo.exceptions import UserError
...@@ -13,53 +13,50 @@ class FumocStockProductionLot(models.Model): ...@@ -13,53 +13,50 @@ class FumocStockProductionLot(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Business method # Business method
# ------------------------------------------------------ # ------------------------------------------------------
def compute_expiration_date(self): def _get_dates(self, product_id=None, lotname=None):
""" """Replaces existing method."""
Check if prefix is known in conf + if suffix is readable mapped_fields = {
-> compute expiration date and other dates if needed 'expiration_date': 'expiration_time',
""" 'use_date': 'use_time',
'removal_date': 'removal_time',
'alert_date': 'alert_time'
}
res = dict.fromkeys(mapped_fields, False)
product = self.env['product.product'].browse(product_id) or self.product_id
lot_name = lotname or self.name
if product and lot_name:
if not self.env.user.company_id.year_reference_lot: if not self.env.user.company_id.year_reference_lot:
raise UserError('L\'année de référence pour les lots n\'a pas été ' raise UserError('L\'année de référence pour les lots n\'a pas été '
'configurée !') 'configurée !')
prefix = re.findall('([a-zA-Z ]*)\d*.*', self.name)[0] suffix = re.findall('([\d]+)\D*', lot_name)[-1]
existing_prefix = self.env['fumoc.lot.prefix.dlc'].search([
('prefix', '=', prefix)
])
suffix = re.findall('([\d]+)\D*', self.name)[-1]
if len(suffix) >= 4: if len(suffix) >= 4:
readable_suffix = suffix[-4:] readable_suffix = suffix[-4:]
else:
readable_suffix = False
if existing_prefix and readable_suffix:
dlc = existing_prefix.dlc
year_ref = self.env.user.company_id.year_reference_lot year_ref = self.env.user.company_id.year_reference_lot
year_index = int(readable_suffix[:1]) year_index = int(readable_suffix[:1])
year = year_ref + year_index year = year_ref + year_index
quantieme = int(readable_suffix[1:]) quantieme = int(readable_suffix[1:])
production_date = datetime.datetime(year, 1, 1) + \ production_date = datetime.datetime(year, 1, 1) + \
datetime.timedelta(days=quantieme-1) datetime.timedelta(days=quantieme-1)
expiration_date = production_date + datetime.timedelta(days=dlc) for field in mapped_fields:
time_delta = expiration_date - self.expiration_date duration = getattr(product, mapped_fields[field])
vals = self._get_date_values(time_delta) if duration:
vals['expiration_date'] = expiration_date date = production_date + datetime.timedelta(days=duration)
self.update(vals) res[field] = fields.Datetime.to_string(date)
return res
# Assign dates according to products data
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
dates = self._get_dates(vals.get('product_id') or self.env.context.get('default_product_id'), vals.get('name') or self.env.context.get('default_name'))
for d in dates:
if not vals.get(d):
vals[d] = dates[d]
return super().create(vals_list)
# ------------------------------------------------------
# Onchange
# ------------------------------------------------------
@api.onchange('name') @api.onchange('name')
def _onchange_name(self): def _onchange_name(self):
if self.create_date: dates_dict = self._get_dates()
self.compute_expiration_date() for field, value in dates_dict.items():
setattr(self, field, value)
# ------------------------------------------------------
# Override parent
# ------------------------------------------------------
@api.model_create_multi
def create(self, vals_list):
"""
Override create to call compute_expiration_date on created lot
"""
res = super(FumocStockProductionLot, self).create(vals_list)
res.compute_expiration_date()
return res
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
"access_fumoc_lot_prefix_dlc_group_partner_manager","fumoc_lot_prefix_dlc group_partner_manager","model_fumoc_lot_prefix_dlc","stock.group_stock_manager",1,1,1,1
"access_fumoc_lot_prefix_dlc_group_user","fumoc_lot_prefix_dlc group_user","model_fumoc_lot_prefix_dlc","base.group_user",1,0,0,0
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="action_fumoc_lot_prefix_dlc" model="ir.actions.act_window">
<field name="name">Lots/DLC</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">fumoc.lot.prefix.dlc</field>
<field name="view_mode">tree</field>
</record>
<record id="fumoc_lot_prefix_dlc_view_tree" model="ir.ui.view">
<field name="name">fumoc_lot_prefix_dlc_view_tree</field>
<field name="model">fumoc.lot.prefix.dlc</field>
<field name="arch" type="xml">
<tree editable="top" string="Lots / DLC">
<field name="name"/>
<field name="prefix"/>
<field name="dlc"/>
</tree>
</field>
</record>
<menuitem id="menu_fumoc_lot_prefix_dlc" name="Lots / DLC" parent="stock.menu_stock_config_settings"
sequence="10" action="action_fumoc_lot_prefix_dlc"/>
</data>
</odoo>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter