File: project_project.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (42 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models, _
from odoo.osv.expression import AND


class ProjectProject(models.Model):
    _inherit = 'project.project'

    def action_open_deliveries(self):
        self.ensure_one()
        return self._get_picking_action(_('From WH'), 'outgoing')

    def action_open_receipts(self):
        self.ensure_one()
        return self._get_picking_action(_('To WH'), 'incoming')

    def action_open_all_pickings(self):
        self.ensure_one()
        return self._get_picking_action(_('Stock Moves'))

    def _get_picking_action(self, action_name, picking_type=None):
        domain = [('project_id', '=', self.id)]
        context = {'default_project_id': self.id}
        if picking_type:
            domain = AND([domain, [('picking_type_id.code', '=', picking_type)]])
            context['restricted_picking_type_code'] = picking_type
            if picking_type == 'outgoing':
                context['default_partner_id'] = self.partner_id.id
        return {
            'name': action_name,
            'type': 'ir.actions.act_window',
            'res_model': 'stock.picking',
            'views': [[False, 'list'], [False, 'form'], [False, 'kanban']],
            'domain': domain,
            'context': context,
            'help': self.env['ir.ui.view']._render_template(
                'stock.help_message_template', {
                    'picking_type_code': picking_type,
                }
            ),
        }