Skip to content
This repository was archived by the owner on Jan 24, 2018. It is now read-only.

Commit 400f151

Browse files
author
Ted Salmon
committed
[IMP] sale_clouder: Fixes per PR
* Update license to AGPL * Add model `_description` * Clean up lint issues * Improve usage metric aggregation logic
1 parent 8c7645c commit 400f151

12 files changed

+45
-50
lines changed

sale_clouder/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
2-
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
33
:alt: License: AGPL-3
44

55
============
@@ -19,7 +19,7 @@ Bug Tracker
1919
===========
2020

2121
Bugs are tracked on `GitHub Issues
22-
<https://github.com/clouder/clouder/issues>`_.
22+
<https://github.com/clouder-community/clouder>`_.
2323

2424
Contributors
2525
------------

sale_clouder/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2016 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from . import models

sale_clouder/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2016 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44
{
55
"name": "Sale - Clouder",
66
"summary": "Provides the ability to sell Clouder instances.",

sale_clouder/data/contract_line_qty_formula.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Copyright 2016 LasLabs Inc.
3-
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
3+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
44

55
<odoo>
66

sale_clouder/data/sale_clouder.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Copyright 2016 LasLabs Inc.
3-
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
3+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
44

5-
<odoo>
6-
<data noupdate="1">
5+
<odoo noupdate="1">
76

87
<record id="seq_clouder_contract" model="ir.sequence">
98
<field name="name">Clouder Contract</field>
@@ -12,6 +11,4 @@
1211
<field name="padding">8</field>
1312
</record>
1413

15-
</data>
16-
1714
</odoo>

sale_clouder/models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2016 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from . import clouder_contract
66
from . import clouder_contract_line

sale_clouder/models/clouder_contract.py

+31-34
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2016-2017 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
import logging
66

7-
from odoo import _, api, fields, models
7+
from odoo import api, fields, models
88

99

1010
_logger = logging.getLogger(__name__)
@@ -14,6 +14,7 @@ class ClouderContract(models.Model):
1414
""" It provides formulas specific to billing Clouder contracts. """
1515

1616
_name = 'clouder.contract'
17+
_description = 'Clouder Contracts'
1718
_inherits = {'account.analytic.account': 'ref_contract_id'}
1819

1920
ref_contract_id = fields.Many2one(
@@ -35,7 +36,7 @@ def invoice_policy_map(self):
3536
""" It returns a mapping of invoice policies to processing methods.
3637
3738
Returns:
38-
(dict) Mapping keyed by invoice policy type, pointing to the
39+
dict: Mapping keyed by invoice policy type, pointing to the
3940
method that should determine the quantity to use for
4041
invoicing.
4142
The method will receive the recurring contract line and the
@@ -59,31 +60,29 @@ def get_invoice_line_quantity(self, account, account_line, invoice):
5960
6061
.. code-block:: python
6162
62-
result = env['clouder.contract'].get_invoice_line_quantity(
63-
contract, line, invoice,
64-
)
63+
result = env['clouder.contract'].get_invoice_line_quantity(
64+
contract, line, invoice,
65+
)
6566
6667
Args:
67-
account (account.analytic.account): Contract that recurring
68+
account (AccountAnalyticAccount): Contract that recurring
6869
invoice line belongs to. This is called
69-
account_line (account.analytic.invoice.line): Recurring invoice
70+
account_line (AccountAnalyticInvoiceLine): Recurring invoice
7071
line being referenced.
71-
invoice (account.invoice): Invoice that is being created.
72+
invoice (AccountInvoice): Invoice that is being created.
7273
Returns:
73-
(int) Quantity to use on invoice line in the UOM defined on the
74+
int: Quantity to use on invoice line in the UOM defined on the
7475
``contract_line``.
7576
"""
7677
invoice_policy = account_line.product_id.invoice_policy
7778
invoice_policy_map = self.invoice_policy_map
7879
try:
7980
method = invoice_policy_map[invoice_policy]
8081
except KeyError:
81-
_logger.info(_(
82+
_logger.info(
8283
'No calculation method found for invoice policy "%s". '
83-
'Defaulting to Flat Rate instead.'
84-
) % (
85-
invoice_policy,
86-
))
84+
'Defaulting to Flat Rate instead.', invoice_policy
85+
)
8786
method = invoice_policy_map['order']
8887
return method(account_line, invoice)
8988

@@ -92,14 +91,15 @@ def _create_default_vals(self, account):
9291
""" It returns default values to create and link new ClouderContracts.
9392
9493
Args:
95-
account (account.analytic.account): Account that ClouderContract
94+
account (AccountAnalyticAccount): Account that ClouderContract
9695
will reference.
9796
Returns:
98-
(dict) Values fed to ``create`` in ``_get_contract_by_account``.
97+
dict: Values fed to ``create`` in ``_get_contract_by_account``.
9998
"""
10099
number = self.env['ir.sequence'].next_by_code('clouder.contract')
101100
# Default to the current users company if not set
102-
company_id = account.company_id.id or self.env.user.company_id.id
101+
company_id = (account.company_id and account.company_id.id or
102+
self.env.user.company_id.id)
103103
return {
104104
'name': number,
105105
'company_id': company_id,
@@ -111,11 +111,11 @@ def _get_contract_by_account(self, account, create=False):
111111
""" It returns the ClouderContract or possibly creates a new one.
112112
113113
Args:
114-
account: (account.analytic.account) Contract to search by.
114+
account: (AccountAnalyticAccount) Contract to search by.
115115
create: (bool) True will create a new ClouderContract if one does
116116
not already exist.
117117
Returns:
118-
(clouder.contract) Clouder contract associated with ``account``.
118+
clouder.contract: Clouder contract associated with ``account``.
119119
"""
120120
contract = self.search([('ref_contract_id', '=', account.id)])
121121
if create and not contract:
@@ -126,11 +126,11 @@ def _get_contract_by_account(self, account, create=False):
126126
def _get_quantity_flat(self, account_line, invoice):
127127
""" It returns the base quantity with no calculations
128128
Args:
129-
account_line (account.analytic.invoice.line): Recurring invoice
129+
account_line (AccountAnalyticInvoiceLine): Recurring invoice
130130
line being referenced.
131-
invoice (account.invoice): Invoice that is being created.
131+
invoice (AccountInvoice): Invoice that is being created.
132132
Returns:
133-
(float) Quantity with no calculations performed
133+
float: Quantity with no calculations performed
134134
"""
135135
return account_line.quantity
136136

@@ -139,11 +139,11 @@ def _get_quantity_threshold(self, account_line, invoice):
139139
""" It functions like flat rate for the most part
140140
141141
Args:
142-
account_line (account.analytic.invoice.line): Recurring invoice
142+
account_line (AccountAnalyticInvoiceLine): Recurring invoice
143143
line being referenced.
144-
invoice (account.invoice): Invoice that is being created.
144+
invoice (AccountInvoice): Invoice that is being created.
145145
Returns:
146-
(float) Quantity to use on invoice line in the UOM defined on the
146+
float: Quantity to use on invoice line in the UOM defined on the
147147
``contract_line``.
148148
"""
149149
return account_line.quantity
@@ -152,14 +152,13 @@ def _get_quantity_threshold(self, account_line, invoice):
152152
def _get_quantity_usage(self, account_line, invoice):
153153
""" It provides a quantity based on unbilled and used metrics
154154
Args:
155-
account_line (account.analytic.invoice.line): Recurring invoice
155+
account_line (AccountAnalyticInvoiceLine): Recurring invoice
156156
line being referenced.
157-
invoice (account.invoice): Invoice that is being created.
157+
invoice (AccountInvoice): Invoice that is being created.
158158
Returns:
159-
(float) Quantity to use on invoice line in the UOM defined on the
159+
float: Quantity to use on invoice line in the UOM defined on the
160160
``contract_line``.
161161
"""
162-
usage = 0
163162
vals = account_line.metric_interface_id.metric_value_ids
164163
inv_date = fields.Datetime.from_string(invoice.date_invoice)
165164
inv_delta = self.ref_contract_id.get_relative_delta(
@@ -174,7 +173,5 @@ def filter(rec):
174173
start = fields.Datetime.from_string(rec.date_start)
175174
end = fields.Datetime.from_string(rec.date_end)
176175
return start >= start_date and end <= inv_date
177-
usage_values = vals.filtered(filter)
178-
for val in usage_values:
179-
usage += val.value
180-
return usage
176+
177+
return sum(vals.filtered(filter).mapped('value')) or 0.0

sale_clouder/models/clouder_contract_line.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ClouderContractLine(models.Model):
99
""" It provides the link between billing and Clouder Services. """
1010

1111
_name = 'clouder.contract.line'
12+
_description = 'Clouder Contract Lines'
1213
_inherits = {'account.analytic.invoice.line': 'contract_line_id'}
1314

1415
contract_line_id = fields.Many2one(

sale_clouder/models/product_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2016 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from odoo import fields, models
66

sale_clouder/tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2017 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from . import test_clouder_contract
66
from . import test_product_template

sale_clouder/tests/test_clouder_contract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2017 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from odoo.tests.common import TransactionCase
66

sale_clouder/tests/test_product_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright 2017 LasLabs Inc.
3-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from odoo.tests.common import TransactionCase
66

0 commit comments

Comments
 (0)