Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

OCA / sale-workflow / 5632

16 Oct 2019 - 11:47 coverage decreased (-5.4%) to 84.344%
5632

Pull #819

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
[MIG] sale_rental: Migration to 11.0
Pull Request #819: [11.0] [MIG] sale_rental

210 of 391 new or added lines in 6 files covered. (53.71%)

2198 of 2606 relevant lines covered (84.34%)

1.69 hits per line

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

37.84
/sale_rental/wizard/create_rental_product.py
1
# Copyright 2014-2016 Akretion (http://www.akretion.com)
2
# @author Alexis de Lattre <alexis.delattre@akretion.com>
3
# Copyright 2016 Sodexis (http://sodexis.com)
4
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5

6
from odoo import models, fields, api, _
2×
7
import odoo.addons.decimal_precision as dp
2×
8

9

10
class CreateRentalProduct(models.TransientModel):
2×
11
    _name = 'create.rental.product'
2×
12
    _description = 'Create the Rental Service Product'
2×
13

14
    @api.model
2×
15
    def _default_name(self):
NEW
16
        assert self.env.context.get('active_model') == 'product.product',\
!
17
            'Wrong underlying model, should be product.product'
NEW
18
        hw_product = self.env['product.product'].browse(
!
19
            self.env.context['active_id'])
NEW
20
        return _('Rental of a %s') % hw_product.name
!
21

22
    @api.model
2×
23
    def _default_code(self):
NEW
24
        assert self.env.context.get('active_model') == 'product.product',\
!
25
            'Wrong underlying model, should be product.product'
NEW
26
        hw_product = self.env['product.product'].browse(
!
27
            self.env.context['active_id'])
NEW
28
        if hw_product.default_code:
!
NEW
29
            return _('RENT-%s') % hw_product.default_code
!
30
        else:
NEW
31
            return ''
!
32

33
    sale_price_per_day = fields.Float(
2×
34
        string='Rental Price per Day', required=True,
35
        digits=dp.get_precision('Product Price'), default=1.0)
36
    name = fields.Char(
2×
37
        string='Product Name', size=64, required=True,
38
        default=_default_name)
39
    default_code = fields.Char(
2×
40
        string='Default Code', size=16, default=_default_code)
41
    categ_id = fields.Many2one(
2×
42
        'product.category', string='Product Category', required=True)
43
    copy_image = fields.Boolean(string='Copy Product Image')
2×
44

45
    @api.model
2×
46
    def _prepare_rental_product(self):
NEW
47
        assert self.env.context.get('active_model') == 'product.product',\
!
48
            'Wrong underlying model, should be product.product'
NEW
49
        hw_product_id = self.env.context.get('active_id')
!
NEW
50
        assert hw_product_id, 'Active ID is not set'
!
NEW
51
        pp_obj = self.env['product.product']
!
NEW
52
        hw_product = pp_obj.browse(hw_product_id)
!
NEW
53
        day_uom_id = self.env.ref('product.product_uom_day').id
!
NEW
54
        vals = {
!
55
            'type': 'service',
56
            'sale_ok': True,
57
            'purchase_ok': False,
58
            'uom_id': day_uom_id,
59
            'uom_po_id': day_uom_id,
60
            'list_price': self.sale_price_per_day,
61
            'name': self.name,
62
            'default_code': self.default_code,
63
            'rented_product_id': hw_product_id,
64
            'must_have_dates': True,
65
            'categ_id': self.categ_id.id,
66
            'invoice_policy': 'order',
67
        }
NEW
68
        if self.copy_image:
!
NEW
69
            vals['image'] = hw_product.image
!
NEW
70
        return vals
!
71

72
    @api.multi
2×
73
    def create_rental_product(self):
NEW
74
        self.ensure_one()
!
NEW
75
        pp_obj = self.env['product.product']
!
76
        #  check that a rental product doesn't already exists ?
NEW
77
        product = pp_obj.create(self._prepare_rental_product())
!
NEW
78
        action = {
!
79
            'name': pp_obj._description,
80
            'type': 'ir.actions.act_window',
81
            'res_model': pp_obj._name,
82
            'view_mode': 'form,tree,kanban',
83
            'nodestroy': False,  # Close the wizard pop-up
84
            'target': 'current',
85
            'res_id': product.id,
86
        }
NEW
87
        return action
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC