-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] fieldservice_account_analytic: Contractor costs
- Loading branch information
1 parent
5c93b75
commit 3dcd910
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
account_move, | ||
analytic_account, | ||
fsm_location, | ||
fsm_order_cost, | ||
fsm_order, | ||
fsm_route, | ||
res_company, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class FsmOrderCost(models.Model): | ||
_name = "fsm.order.cost" | ||
_inherit = "analytic.mixin" | ||
_description = "Fsm Order Cost" | ||
|
||
fsm_order_id = fields.Many2one( | ||
comodel_name="fsm.order", | ||
required=True, | ||
) | ||
price_unit = fields.Float( | ||
string="Unit Price", | ||
required=True, | ||
) | ||
quantity = fields.Float( | ||
required=True, | ||
default=1, | ||
) | ||
product_id = fields.Many2one( | ||
comodel_name="product.product", | ||
required=True, | ||
) | ||
|
||
@api.onchange("product_id") | ||
def onchange_product_id(self): | ||
for cost in self: | ||
if not cost.product_id: | ||
continue | ||
cost.price_unit = cost.product_id.standard_price | ||
|
||
def _default_analytic_distribution(self): | ||
total_distribution = {} | ||
for order in self.fsm_order_id: | ||
if not order: | ||
return {} | ||
order_count = len(self.fsm_order_id) | ||
percentage_per_order = 100 / order_count | ||
|
||
analytic_account_ids = [] | ||
|
||
order_id = self.env["fsm.order"].browse(order.id) | ||
|
||
analytic_account_id = order_id.location_id.analytic_account_id.id | ||
if analytic_account_id: | ||
analytic_account_ids.append(str(analytic_account_id)) | ||
|
||
analytic_account_id = order_id.analytic_account_id.id | ||
if analytic_account_id: | ||
analytic_account_ids.append(str(analytic_account_id)) | ||
|
||
if analytic_account_ids: | ||
distribution_key = ",".join(analytic_account_ids) | ||
total_distribution[distribution_key] = percentage_per_order | ||
|
||
self.analytic_distribution = total_distribution | ||
|
||
return total_distribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<odoo> | ||
<record model="ir.model.access" id="fsm_order_cost_access_base_user"> | ||
<field name="name">fsm.order.cost access base user</field> | ||
<field name="model_id" ref="model_fsm_order_cost" /> | ||
<field name="group_id" ref="base.group_user" /> | ||
<field name="perm_read" eval="1" /> | ||
<field name="perm_create" eval="0" /> | ||
<field name="perm_write" eval="0" /> | ||
<field name="perm_unlink" eval="0" /> | ||
</record> | ||
<record model="ir.model.access" id="fsm_order_cost_access_fieldservice_user"> | ||
<field name="name">fsm.order.cost access fieldservice user</field> | ||
<field name="model_id" ref="model_fsm_order_cost" /> | ||
<field name="group_id" ref="fieldservice.group_fsm_user" /> | ||
<field name="perm_read" eval="1" /> | ||
<field name="perm_create" eval="1" /> | ||
<field name="perm_write" eval="1" /> | ||
<field name="perm_unlink" eval="1" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters