• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OCA / stock-logistics-warehouse / 3456

pending completion
3456

push

travis-ci

web-flow
Merge pull request #541 from sebalix/11.0-fix-stock_move_location

[FIX] stock_move_location: fix the 'group_lines()' method

7 of 7 new or added lines in 1 file covered. (100.0%)

2655 of 2883 relevant lines covered (92.09%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.67
/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint.py
1
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
2
#   (http://www.eficent.com)
3
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4

5
from odoo import api, fields, models, _
2✔
6
from odoo.exceptions import UserError, ValidationError
2✔
7

8

9
class MakeProcurementOrderpoint(models.TransientModel):
2✔
10
    _name = 'make.procurement.orderpoint'
2✔
11
    _description = 'Make Procurements from Orderpoints'
2✔
12

13
    item_ids = fields.One2many(
2✔
14
        'make.procurement.orderpoint.item',
15
        'wiz_id', string='Items')
16

17
    @api.model
2✔
18
    def _prepare_item(self, orderpoint):
19
        return {
2✔
20
            'qty': orderpoint.procure_recommended_qty,
21
            'qty_without_security': orderpoint.procure_recommended_qty,
22
            'uom_id': orderpoint.product_uom.id,
23
            'date_planned': orderpoint.procure_recommended_date,  # string
24
            'orderpoint_id': orderpoint.id,
25
            'product_id': orderpoint.product_id.id,
26
            'warehouse_id': orderpoint.warehouse_id.id,
27
            'location_id': orderpoint.location_id.id
28
        }
29

30
    @api.model
2✔
31
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
2✔
32
                        submenu=False):
33
        if not self.user_has_groups(
×
34
                "stock_orderpoint_manual_procurement.group_change_orderpoint_procure_qty"): # noqa
35
            # Redirect to readonly qty form view
36
            view_id = self.env.ref(
×
37
                'stock_orderpoint_manual_procurement.view_make_procure_without_security').id # noqa
38
        return super(MakeProcurementOrderpoint, self).fields_view_get(
×
39
            view_id=view_id, view_type=view_type, toolbar=toolbar,
40
            submenu=submenu)
41

42
    @api.model
2✔
43
    def default_get(self, fields):
44
        res = super(MakeProcurementOrderpoint, self).default_get(fields)
2✔
45
        orderpoint_obj = self.env['stock.warehouse.orderpoint']
2✔
46
        orderpoint_ids = self.env.context['active_ids'] or []
2✔
47
        active_model = self.env.context['active_model']
2✔
48

49
        if not orderpoint_ids:
2✔
50
            return res
×
51
        assert active_model == 'stock.warehouse.orderpoint', \
2✔
52
            'Bad context propagation'
53

54
        items = []
2✔
55
        for line in orderpoint_obj.browse(orderpoint_ids):
2✔
56
            items.append([0, 0, self._prepare_item(line)])
2✔
57
        res['item_ids'] = items
2✔
58
        return res
2✔
59

60
    @api.multi
2✔
61
    def make_procurement(self):
62
        self.ensure_one()
2✔
63
        errors = []
2✔
64
        # User requesting the procurement is passed by context to be able to
65
        # update final MO, PO or trasfer with that information.
66
        pg_obj = self.env['procurement.group'].with_context(
2✔
67
            requested_uid=self.env.user)
68
        for item in self.item_ids:
2✔
69
            if not item.qty:
2✔
70
                raise ValidationError(_("Quantity must be positive."))
×
71
            if not item.orderpoint_id:
2✔
72
                raise ValidationError(_("No reordering rule found!"))
×
73
            values = item.orderpoint_id._prepare_procurement_values(item.qty)
2✔
74
            values['date_planned'] = fields.Datetime.to_string(
2✔
75
                fields.Date.from_string(item.date_planned))
76
            # Run procurement
77
            try:
2✔
78
                pg_obj.run(
2✔
79
                    item.orderpoint_id.product_id,
80
                    item.qty,
81
                    item.uom_id,
82
                    item.orderpoint_id.location_id,
83
                    item.orderpoint_id.name,
84
                    item.orderpoint_id.name,
85
                    values
86
                )
87
            except UserError as error:
×
88
                    errors.append(error.name)
×
89
            if errors:
2✔
90
                raise UserError('\n'.join(errors))
×
91
        return {'type': 'ir.actions.act_window_close'}
2✔
92

93

94
class MakeProcurementOrderpointItem(models.TransientModel):
2✔
95
    _name = 'make.procurement.orderpoint.item'
2✔
96
    _description = 'Make Procurements from Orderpoint Item'
2✔
97

98
    wiz_id = fields.Many2one(
2✔
99
        'make.procurement.orderpoint', string='Wizard', required=True,
100
        ondelete='cascade', readonly=True)
101

102
    qty = fields.Float(string='Quantity')
2✔
103
    qty_without_security = fields.Float(string='Quantity')
2✔
104

105
    uom_id = fields.Many2one(string='Unit of Measure',
2✔
106
                             comodel_name='product.uom')
107
    date_planned = fields.Date(string='Planned Date', required=False)
2✔
108

109
    orderpoint_id = fields.Many2one(string='Reordering rule',
2✔
110
                                    comodel_name='stock.warehouse.orderpoint',
111
                                    readonly=False)
112
    product_id = fields.Many2one(string='Product',
2✔
113
                                 comodel_name='product.product',
114
                                 readonly=True)
115
    warehouse_id = fields.Many2one(string='Warehouse',
2✔
116
                                   comodel_name='stock.warehouse',
117
                                   readonly=True)
118
    location_id = fields.Many2one(string='Location',
2✔
119
                                  comodel_name='stock.location',
120
                                  readonly=True)
121

122
    @api.multi
2✔
123
    @api.onchange('uom_id')
2✔
124
    def onchange_uom_id(self):
125
        for rec in self:
×
126
            rec.qty = rec.orderpoint_id.product_uom._compute_quantity(
×
127
                rec.orderpoint_id.procure_recommended_qty, rec.uom_id)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc