Skip to content

Commit

Permalink
Merge pull request OCA#456 from TDu/bssfw-40
Browse files Browse the repository at this point in the history
BSSFW-40 Add serial_owner
  • Loading branch information
yvaucher committed May 7, 2018
2 parents 350b45f + 2fb87b1 commit f638851
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ latest (unreleased)

**Features and Improvements**

* BSSFW-40: Add serial_owner

**Bugfixes**

**Build**
Expand Down
3 changes: 3 additions & 0 deletions odoo/local-src/sf_partner_entity_type/data/entity_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<record model="res.partner.entity.type" id="entity_gov">
<field name="name">Governement</field>
</record>
<record model="res.partner.entity.type" id="entity_dealer">
<field name="name">Dealer</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions odoo/local-src/sf_serial_owner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import models
22 changes: 22 additions & 0 deletions odoo/local-src/sf_serial_owner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "sf_serial_owner",
"description": "Keep track of serial number link to customer and reseller",
"version": "10.0.1.0.0",
"category": "",
"website": "https://camptocamp.com",
"author": "Camptocamp",
"license": "AGPL-3",
"depends": [
"product",
"stock",
"sf_rma",
"sf_partner_entity_type",
],
"data": [
"security/ir.model.access.csv",
"views/serial_owner.xml",
],
}
1 change: 1 addition & 0 deletions odoo/local-src/sf_serial_owner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import serial_owner
60 changes: 60 additions & 0 deletions odoo/local-src/sf_serial_owner/models/serial_owner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import api, fields, models, _
from odoo.exceptions import UserError


class SerialOwner(models.Model):
_name = 'serial.owner'
_inherit = 'mail.thread'

_description = 'Serial number onwership'

serial_number_id = fields.Many2one(
comodel_name='stock.production.lot',
string='Serial Number',
required=True,
)
product_id = fields.Many2one(
related='serial_number_id.product_id',
string='Product',
)
product_name = fields.Char(
related='serial_number_id.product_id.name',
string='Product',
readonly=True,
)
reseller_id = fields.Many2one(
comodel_name='res.partner',
string='Reseller',
domain=lambda self: self._get_reseller_domain(),
track_visibility='onchange',
)
customer_id = fields.Many2one(
comodel_name='res.partner',
string='Customer',
domain=[('customer', '=', True)],
track_visibility='onchange',
)
shipped_to_reseller_on = fields.Date(
string='Shipped on',
track_visibility='onchange',
)
registred_by_customer_on = fields.Date(
string='Registred on',
track_visibility='onchange',
)

@api.multi
def _get_reseller_domain(self):
entity = self.env.ref(
'sf_partner_entity_type.entity_dealer',
raise_if_not_found=False
)
if not entity:
raise UserError(
_("Entity type \"Dealer\" was removed. Please update"
" sf_partner_enityt_type module to restore it."))
return [('entity_type_id', '=', entity.id),
('customer', '=', 'True')]
4 changes: 4 additions & 0 deletions odoo/local-src/sf_serial_owner/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_serial_owner_reader,serial.owner reader,model_serial_owner,sf_rma.group_rma_reader,1,0,0,0
access_serial_owner_user,serial.owner user,model_serial_owner,sf_rma.group_rma_user,1,1,1,0
access_serial_owner_manager,serial.owner reader,model_serial_owner,sf_rma.group_rma_manager,1,1,1,0
85 changes: 85 additions & 0 deletions odoo/local-src/sf_serial_owner/views/serial_owner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_serial_owner_form" model="ir.ui.view">
<field name="name">serial.owner.form</field>
<field name="model">serial.owner</field>
<field name="arch" type="xml">
<form string="Serial Owner">
<header>
</header>
<sheet>
<div class="oe_title">
<label for="serial_number_id" class="oe_edit_only"/>
<h1><field name="serial_number_id"/></h1>
</div>
<group name="main">
<group name="product_info">
<field name="product_name"/>
</group>
<group></group>
<group name="customer_info">
<field name="customer_id"/>
<field name="registred_by_customer_on"/>
</group>
<group name="reseller_info">
<field name="reseller_id"/>
<field name="shipped_to_reseller_on"/>
</group>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>

<record id="view_serial_owner_tree" model="ir.ui.view">
<field name="name">serial.owner.tree</field>
<field name="model">serial.owner</field>
<field name="arch" type="xml">
<tree string="Serial Owner">
<field name="customer_id"/>
<field name="serial_number_id"/>
<field name="product_id"/>
<field name="reseller_id"/>
</tree>
</field>
</record>

<record id="view_serialowner_filter" model="ir.ui.view">
<field name="name">serial.owner.filter</field>
<field name="model">serial.owner</field>
<field name="arch" type="xml">
<search string="Search serial owner">
<field name="serial_number_id" string="Serial number"/>
<field name="product_name" string="Product name"/>
<field name="reseller_id"/>
<field name="customer_id"/>
<group expand="0" string="Group By">
<filter string="Reseller" domain="[]" context="{'group_by':'reseller_id'}"/>
<filter string="Customer" domain="[]" context="{'group_by':'customer_id'}"/>
<filter string="Product" domain="[]" context="{'group_by':'product_id'}"/>
</group>
</search>

</field>
</record>

<record id="action_serial_owner" model="ir.actions.act_window">
<field name="name">Serial Owner</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">serial.owner</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_serial_owner_tree"/>
<field name="search_view_id" ref="view_serialowner_filter"/>
</record>

<menuitem action="action_serial_owner"
id="menu_action_serial_owner"
parent="stock.menu_stock_inventory_control"
sequence="120"/>

</odoo>
10 changes: 10 additions & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,13 @@ migration:
upgrade:
# local-src
- sf_mail
- version: 10.29.0
operations:
post:
- "sh -c 'PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -U $DB_USER -f odoo/songs/upgrade/10_29_0_update.sql $DB_NAME'"
addons:
upgrade:
# local-src
- sf_partner_entity_type
- sf_mail
- sf_serial_owner
5 changes: 5 additions & 0 deletions odoo/songs/upgrade/10_29_0_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- update xmlid for entity_type "Dealer"
-- reuse old entity_type and point new xmlid to it
UPDATE ir_model_data SET res_id = (SELECT res_id FROM ir_model_data WHERE module = '__setup__' AND name = 'res_partner_entity_dealer') WHERE module = 'sf_partner_entity_type' AND name = 'entity_dealer';
-- delete new entity not anymore related to an xmlid
DELETE FROM res_partner_entity_type WHERE name = 'Dealer' AND id != (SELECT res_id FROM ir_model_data WHERE module = 'sf_partner_entity_type' AND name = 'entity_dealer');

0 comments on commit f638851

Please sign in to comment.