diff --git a/beesdoo_purchase/__openerp__.py b/beesdoo_purchase/__openerp__.py index c37e007..50908ce 100644 --- a/beesdoo_purchase/__openerp__.py +++ b/beesdoo_purchase/__openerp__.py @@ -9,24 +9,18 @@ Long description of module's purpose """, - 'author': "Beescoop - Cellule IT", + 'author': "Beescoop - Cellule IT, " + "Coop IT Easy SCRLfs", 'website': "https://github.com/beescoop/Obeesdoo", - # Categories can be used to filter modules in modules listing - # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml - # for the full list 'category': 'Purchase', - 'version': '0.1', + 'version': '9.0.1.1.0', - # any module necessary for this one to work correctly - 'depends': ['base','purchase','beesdoo_product'], + 'depends': ['base', 'purchase', 'beesdoo_product'], - # always loaded 'data': [ 'views/purchase_order.xml', 'security/ir.model.access.csv', 'report/report_purchaseorder.xml', ], - # only loaded in demonstration mode - 'demo': [], -} \ No newline at end of file +} diff --git a/beesdoo_purchase/migrations/9.0.1.1.0/post-migrate.py b/beesdoo_purchase/migrations/9.0.1.1.0/post-migrate.py new file mode 100644 index 0000000..707e4a8 --- /dev/null +++ b/beesdoo_purchase/migrations/9.0.1.1.0/post-migrate.py @@ -0,0 +1,12 @@ +# coding: utf-8 + + +def migrate(cr, version): + """Set the new supervisor_id field if this one is empty.""" + cr.execute( + """ + UPDATE purchase_order + SET supervisor_id = create_uid + WHERE supervisor_id IS NULL + """ + ) diff --git a/beesdoo_purchase/models/__init__.py b/beesdoo_purchase/models/__init__.py index 667b7e3..cacb10c 100644 --- a/beesdoo_purchase/models/__init__.py +++ b/beesdoo_purchase/models/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - -import purchase_order \ No newline at end of file +from . import purchase, purchase_order diff --git a/beesdoo_purchase/models/purchase.py b/beesdoo_purchase/models/purchase.py new file mode 100644 index 0000000..0832d37 --- /dev/null +++ b/beesdoo_purchase/models/purchase.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +from openerp import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + # create_uid must mirror the supervisor_id value. + # create_uid is a magic field that belongs to the ORM that is not + # editable via a form. + create_uid = fields.Many2one( + comodel_name='res.users', + compute='_compute_create_uid', + ) + supervisor_id = fields.Many2one( + comodel_name='res.users', + string='Responsible', + required=True, + default=lambda self: self.env.user, + ) + + @api.depends('supervisor_id') + def _compute_create_uid(self): + for rec in self: + if rec.supervisor_id: + rec.create_uid = rec.supervisor_id + + @api.multi + def write(self, vals): + if 'supervisor_id' in vals: + new_supervisor = vals['supervisor_id'] + for rec in self: + rec.message_unsubscribe_users( + user_ids=rec.supervisor_id.ids, + ) + rec.message_subscribe_users( + user_ids=[new_supervisor], + subtype_ids=[], + ) + return super(PurchaseOrder, self).write(vals) diff --git a/beesdoo_purchase/views/purchase_order.xml b/beesdoo_purchase/views/purchase_order.xml index d84ab2e..f649d78 100644 --- a/beesdoo_purchase/views/purchase_order.xml +++ b/beesdoo_purchase/views/purchase_order.xml @@ -6,12 +6,34 @@ - + [('main_seller_id','=', parent.partner_id), ('purchase_ok', '=', True)] + + + beesdoo.purchase.order.tree.view + purchase.order + + + + + + + + + + beesdoo.purchase.order.search.view + purchase.order + + + + + + +