diff --git a/__manifest__.py b/__manifest__.py index 1fd024640bf6e5178ab4076a8ca445eeb9711e64..801bb3dcca4174d183dab2ff8f277d5c16b4b57e 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -30,6 +30,7 @@ 'category': 'Custom', 'depends': ['mrp', 'quality_control', 'delivery', 'mrp_production_service', 'stock', 'purchase_requisition'], 'data': [ + 'data/purchase_data.xml', 'security/ir.model.access.csv', 'views/stock_view.xml', 'views/quality_control_view.xml', diff --git a/data/purchase_data.xml b/data/purchase_data.xml new file mode 100644 index 0000000000000000000000000000000000000000..6905ea266489d653ea0ae9c34c4aaf3c7fc7f487 --- /dev/null +++ b/data/purchase_data.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data noupdate="1"> + + <record id="seq_opened_purchase_order" model="ir.sequence"> + <field name="name">Purchase Order</field> + <field name="code">opened.purchase.order</field> + <field name="prefix">POA</field> + <field name="padding">5</field> + <field name="company_id" eval="False"/> + </record> + + </data> +</odoo> diff --git a/i18n/es_AR.po b/i18n/es_AR.po index b1c14b4d95e2e5b79adb437365c63214c58460f5..c2e23dc96436e65d16b7424e4a16c3e41fbc0bc2 100644 --- a/i18n/es_AR.po +++ b/i18n/es_AR.po @@ -144,7 +144,7 @@ msgstr "MO UOM" #. module: emu_custom #: model:ir.model.fields,field_description:emu_custom.field_purchase_order_economic_level msgid "EL" -msgstr "EL" +msgstr "NE" #. module: emu_custom #: model:ir.model.fields,field_description:emu_custom.field_purchase_order_er_field @@ -153,6 +153,7 @@ msgstr "ER" #. module: emu_custom #: model:ir.model.fields,field_description:emu_custom.field_purchase_order_effectiveness +#, python-format msgid "Effectiviness" msgstr "Efectividad" @@ -165,3 +166,10 @@ msgstr "Órdenes de compra abiertas" #: model:ir.actions.act_window,name:emu_custom.action_opened_purchase_order msgid "Purchase Orders" msgstr "Órdenes de compra" + +#. module: emu_custom +#: code:addons/emu_custom/models/purchase.py:88 +#: code:addons/emu_custom/models/purchase.py:102 +#, python-format +msgid "Check the format of the %s field it must be MM/YYYY" +msgstr "Revise el formato del campo %s, su formato tiene que ser del tipo MM/AAAA" diff --git a/models/purchase.py b/models/purchase.py index 91677a047a8a013d9140a5fa91d91fd8c2da5245..fd1760970185e9ad1037e41d1cf848d5160af179 100644 --- a/models/purchase.py +++ b/models/purchase.py @@ -24,7 +24,7 @@ from odoo import api, fields, models, _ from odoo.addons.purchase_requisition.models.purchase_requisition import ProcurementRule as PR from odoo.addons.stock.models.procurement import ProcurementGroup as PG from odoo.http import request -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError import logging logger = logging.getLogger(__name__) @@ -73,6 +73,47 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).create(values) return res + @api.constrains('economic_level') + def economic_level_validate(self): + for rec in self: + if rec.is_opened and rec.economic_level: + economic_level = rec.economic_level + if len(economic_level) == 0: + continue + if len(economic_level) == 6 and economic_level.isdigit() and int(economic_level[0:2]) <= 12: + rec.economic_level = economic_level[0:2] + '/' + economic_level[2:] + continue + if len(economic_level) == 7 and (economic_level[0:2] + economic_level[3:]).isdigit() and int(economic_level[0:2]) <= 12 and \ + economic_level[2] == '/': + continue + raise ValidationError(_('Check the format of the %s field it must be MM/YYYY') % 'economic level') + + @api.constrains('effectiveness') + def effectiveness_validate(self): + for rec in self: + if rec.is_opened and rec.effectiveness: + effectiveness = rec.effectiveness + if len(effectiveness) == 0: + continue + if len(effectiveness) == 6 and effectiveness.isdigit() and int(effectiveness[0:2]) <= 12: + rec.effectiveness = effectiveness[0:2] + '/' + effectiveness[2:] + continue + if len(effectiveness) == 7 and (effectiveness[0:2] + effectiveness[3:]).isdigit() and \ + int(effectiveness[0:2]) <= 12 and effectiveness[2] == '/': + continue + raise ValidationError(_('Check the format of the %s field it must be MM/YYYY') % (_('effectiveness'))) + + @api.model + def create(self, vals): + if vals.get('name', 'New') == 'New' and vals.get('is_opened', False): + vals['name'] = self.env['ir.sequence'].next_by_code('opened.purchase.order') or '/' + return super(PurchaseOrder, self).create(vals) + + @api.multi + def unlink(self): + if self.is_opened: + self.button_cancel() + return super(PurchaseOrder, self).unlink() class ProcurementGroup(models.Model): _inherit = "procurement.group"