Fix states of Sector's fields and move sector's field from variant to product's template

This commit is contained in:
Guillem Barba 2014-10-09 19:29:32 +02:00
parent fa244353e3
commit b608c6edaa
7 changed files with 146 additions and 121 deletions

View File

@ -7,10 +7,10 @@ from .sector import *
def register():
Pool.register(
Sector,
PartySector,
Party,
ProductSector,
Product,
PartySector,
Template,
TemplateSector,
module='party_sector', type_='model')
Pool.register(
OpenSector,

View File

@ -13,7 +13,7 @@ msgid "The name of a party sector must be unique by parent."
msgstr "El nom del sector ha de ser únic per pare."
msgctxt "field:party.party,products:"
msgid "products"
msgid "Products"
msgstr "Productes"
msgctxt "field:party.party,related_sectors:"
@ -96,50 +96,54 @@ msgctxt "field:party.sector,write_uid:"
msgid "Write User"
msgstr "Usuari modificació"
msgctxt "field:product.product,parties:"
msgctxt "field:product.template,parties:"
msgid "Parties"
msgstr "Tercers"
msgctxt "field:product.product,related_sectors:"
msgctxt "field:product.template,related_sectors:"
msgid "Sectors"
msgstr "Sectors"
msgctxt "field:product.product,sectors:"
msgctxt "field:product.template,sectors:"
msgid "Sectors"
msgstr "Sectors"
msgctxt "field:product.product-party.sector,create_date:"
msgctxt "field:product.template-party.sector,create_date:"
msgid "Create Date"
msgstr "Data de creació"
msgctxt "field:product.product-party.sector,create_uid:"
msgctxt "field:product.template-party.sector,create_uid:"
msgid "Create User"
msgstr "Usuari de creació"
msgctxt "field:product.product-party.sector,id:"
msgctxt "field:product.template-party.sector,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "field:product.product-party.sector,product:"
msgid "Product"
msgstr "Productes"
msgctxt "field:product.product-party.sector,rec_name:"
msgctxt "field:product.template-party.sector,rec_name:"
msgid "Name"
msgstr "Nom"
msgctxt "field:product.product-party.sector,sector:"
msgctxt "field:product.template-party.sector,sector:"
msgid "Sector"
msgstr "Sector"
msgctxt "field:product.product-party.sector,write_date:"
msgctxt "field:product.template-party.sector,template:"
msgid "Product Template"
msgstr "Plantilla de producte"
msgctxt "field:product.template-party.sector,write_date:"
msgid "Write Date"
msgstr "Data modificació"
msgctxt "field:product.product-party.sector,write_uid:"
msgctxt "field:product.template-party.sector,write_uid:"
msgid "Write User"
msgstr "Usuari modificació"
msgctxt "model:ir.action,name:act_open_sector"
msgid "Open Sector"
msgstr "Obrir sector"
msgctxt "model:ir.action,name:act_party_product"
msgid "Products"
msgstr "Productes"
@ -149,12 +153,12 @@ msgid "Parties"
msgstr "Tercers"
msgctxt "model:ir.action,name:act_related_party"
msgid "Parties"
msgstr "Tercers"
msgid "Parties by sector"
msgstr "Tercers per sector"
msgctxt "model:ir.action,name:act_related_product"
msgid "Products"
msgstr "Productes"
msgid "Products by sector"
msgstr "Productes per sector"
msgctxt "model:ir.action,name:act_sector_list"
msgid "Sectors"
@ -196,9 +200,9 @@ msgctxt "model:party.sector,name:"
msgid "Sector"
msgstr "Sector"
msgctxt "model:product.product-party.sector,name:"
msgid "Product - Sector"
msgstr "Producte - Sector"
msgctxt "model:product.template-party.sector,name:"
msgid "Product Template - Sector"
msgstr "Plantilla producte - Sector"
msgctxt "view:party.party:"
msgid "Sectors"
@ -211,3 +215,7 @@ msgstr "Sector"
msgctxt "view:party.sector:"
msgid "Sectors"
msgstr "Sectors"
msgctxt "view:product.template:"
msgid "Sectors"
msgstr "Sectors"

View File

@ -13,16 +13,16 @@ msgid "The name of a party sector must be unique by parent."
msgstr "El nombre del sector debe ser único por padre."
msgctxt "field:party.party,products:"
msgid "products"
msgid "Products"
msgstr "Productos"
msgctxt "field:party.party,related_sectors:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "field:party.party,sectors:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "field:party.party-party.sector,create_date:"
msgid "Create Date"
@ -96,50 +96,54 @@ msgctxt "field:party.sector,write_uid:"
msgid "Write User"
msgstr "Usuario modificación"
msgctxt "field:product.product,parties:"
msgctxt "field:product.template,parties:"
msgid "Parties"
msgstr "Terceros"
msgctxt "field:product.product,related_sectors:"
msgctxt "field:product.template,related_sectors:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "field:product.product,sectors:"
msgctxt "field:product.template,sectors:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "field:product.product-party.sector,create_date:"
msgctxt "field:product.template-party.sector,create_date:"
msgid "Create Date"
msgstr "Fecha de creación"
msgctxt "field:product.product-party.sector,create_uid:"
msgctxt "field:product.template-party.sector,create_uid:"
msgid "Create User"
msgstr "Usuario de creación"
msgctxt "field:product.product-party.sector,id:"
msgctxt "field:product.template-party.sector,id:"
msgid "ID"
msgstr "Identificador"
msgctxt "field:product.product-party.sector,product:"
msgid "Product"
msgstr "Productos"
msgctxt "field:product.product-party.sector,rec_name:"
msgctxt "field:product.template-party.sector,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:product.product-party.sector,sector:"
msgctxt "field:product.template-party.sector,sector:"
msgid "Sector"
msgstr "Sector"
msgctxt "field:product.product-party.sector,write_date:"
msgctxt "field:product.template-party.sector,template:"
msgid "Product Template"
msgstr "Plantilla de producto"
msgctxt "field:product.template-party.sector,write_date:"
msgid "Write Date"
msgstr "Fecha modificación"
msgctxt "field:product.product-party.sector,write_uid:"
msgctxt "field:product.template-party.sector,write_uid:"
msgid "Write User"
msgstr "Usuario modificación"
msgctxt "model:ir.action,name:act_open_sector"
msgid "Open Sector"
msgstr "Abrir sector"
msgctxt "model:ir.action,name:act_party_product"
msgid "Products"
msgstr "Productos"
@ -149,44 +153,44 @@ msgid "Parties"
msgstr "Terceros"
msgctxt "model:ir.action,name:act_related_party"
msgid "Parties"
msgstr "Terceros"
msgid "Parties by sector"
msgstr "Terceros por sector"
msgctxt "model:ir.action,name:act_related_product"
msgid "Products"
msgstr "Productos"
msgid "Products by sector"
msgstr "Productos por sector"
msgctxt "model:ir.action,name:act_sector_list"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.action,name:act_sector_list_product"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.action,name:act_sector_tree"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.action,name:act_sector_tree_product"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.ui.menu,name:menu_sector_list"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.ui.menu,name:menu_sector_list_product"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.ui.menu,name:menu_sector_tree"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:ir.ui.menu,name:menu_sector_tree_product"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "model:party.party-party.sector,name:"
msgid "Party - Sector"
@ -196,13 +200,13 @@ msgctxt "model:party.sector,name:"
msgid "Sector"
msgstr "Sector"
msgctxt "model:product.product-party.sector,name:"
msgid "Product - Sector"
msgstr "Producto - Sector"
msgctxt "model:product.template-party.sector,name:"
msgid "Product Template - Sector"
msgstr "Plantilla producto - Sector"
msgctxt "view:party.party:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "view:party.sector:"
msgid "Sector"
@ -210,4 +214,8 @@ msgstr "Sector"
msgctxt "view:party.sector:"
msgid "Sectors"
msgstr "Sectors"
msgstr "Sectores"
msgctxt "view:product.template:"
msgid "Sectors"
msgstr "Sectores"

View File

@ -6,12 +6,12 @@ from trytond.pyson import Eval, PYSONEncoder
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateTransition, StateAction
__all__ = ['Sector', 'PartySector', 'Party', 'ProductSector', 'Product',
__all__ = ['Sector', 'Party', 'PartySector', 'Template', 'TemplateSector',
'OpenSector']
__metaclass__ = PoolMeta
STATES = {
'readonly': Eval('active', False),
'readonly': ~Eval('active', False),
}
DEPENDS = ['active']
@ -99,6 +99,38 @@ class SectorRelatedMixin:
})
class Party(SectorRelatedMixin):
__name__ = 'party.party'
sectors = fields.Many2Many('party.party-party.sector', 'party', 'sector',
'Sectors')
products = fields.Function(fields.Many2Many('product.template', None, None,
'Products'),
'get_products', searcher='search_products')
def get_products(self, name):
pool = Pool()
Template = pool.get('product.template')
products = Template.search([
('sectors', 'child_of', [x.id for x in self.sectors],
'parent'),
])
return [x.id for x in products]
@classmethod
def search_products(cls, name, clause):
pool = Pool()
Template = pool.get('product.template')
products = Template.search([tuple(('id',)) + tuple(clause[1:])])
sectors = set()
for product in products:
for sector in product.sectors:
sectors.add(sector.id)
return [('sectors', 'in', list(sectors))]
class PartySector(ModelSQL):
'Party - Sector'
__name__ = 'party.party-party.sector'
@ -109,50 +141,10 @@ class PartySector(ModelSQL):
required=True, ondelete='CASCADE')
class Party(SectorRelatedMixin):
__name__ = 'party.party'
class Template(SectorRelatedMixin):
__name__ = 'product.template'
sectors = fields.Many2Many('party.party-party.sector', 'party', 'sector',
'Sectors')
products = fields.Function(fields.Many2Many('product.product', None, None,
'products'),
'get_products', searcher='search_products')
def get_products(self, name):
pool = Pool()
Product = pool.get('product.product')
products = Product.search([
('sectors', 'child_of', [x.id for x in self.sectors],
'parent'),
])
return [x.id for x in products]
@classmethod
def search_products(cls, name, clause):
pool = Pool()
Product = pool.get('product.product')
products = Product.search([tuple(('id',)) + tuple(clause[1:])])
sectors = set()
for product in products:
for sector in product.sectors:
sectors.add(sector.id)
return [('sectors', 'in', list(sectors))]
class ProductSector(ModelSQL):
'Product - Sector'
__name__ = 'product.product-party.sector'
product = fields.Many2One('product.product', 'Product', select=True,
required=True, ondelete='CASCADE')
sector = fields.Many2One('party.sector', 'Sector', select=True,
required=True, ondelete='CASCADE')
class Product(SectorRelatedMixin):
__name__ = 'product.product'
sectors = fields.Many2Many('product.product-party.sector', 'product',
sectors = fields.Many2Many('product.template-party.sector', 'template',
'sector', 'Sectors')
parties = fields.Function(fields.Many2Many('party.party', None, None,
'Parties'),
@ -179,6 +171,16 @@ class Product(SectorRelatedMixin):
return [('sectors', 'in', list(sectors))]
class TemplateSector(ModelSQL):
'Product Template - Sector'
__name__ = 'product.template-party.sector'
template = fields.Many2One('product.template', 'Product Template',
select=True, required=True, ondelete='CASCADE')
sector = fields.Many2One('party.sector', 'Sector', select=True,
required=True, ondelete='CASCADE')
class OpenSector(Wizard):
'Open Sector Wizard'
__name__ = 'party.sector.open'

View File

@ -3,17 +3,20 @@
copyright notices and license terms. -->
<tryton>
<data>
<!-- party.sector -->
<record model="ir.ui.view" id="sector_view_form">
<field name="model">party.sector</field>
<field name="type">form</field>
<field name="name">sector_form</field>
</record>
<record model="ir.ui.view" id="sector_view_tree">
<field name="model">party.sector</field>
<field name="type">tree</field>
<field name="field_childs">childs</field>
<field name="name">sector_tree</field>
</record>
<record model="ir.ui.view" id="sector_view_list">
<field name="model">party.sector</field>
<field name="type">tree</field>
@ -21,6 +24,7 @@
<field name="name">sector_list</field>
</record>
<!-- party.party -->
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="type">form</field>
@ -28,11 +32,12 @@
<field name="name">party_form</field>
</record>
<record model="ir.ui.view" id="product_view_form">
<field name="model">product.product</field>
<!-- product.template -->
<record model="ir.ui.view" id="product_template_view_form">
<field name="model">product.template</field>
<field name="type">form</field>
<field name="inherit" ref="product.product_view_form"/>
<field name="name">product_form</field>
<field name="inherit" ref="product.template_view_form"/>
<field name="name">product_template_form</field>
</record>
<!-- Relates -->
@ -43,7 +48,7 @@
<record model="ir.action.act_window" id="act_related_product">
<field name="name">Products by sector</field>
<field name="res_model">product.product</field>
<field name="res_model">product.template</field>
</record>
<record model="ir.action.wizard" id="act_open_sector">
@ -59,7 +64,7 @@
<record model="ir.action.act_window" id="act_party_product">
<field name="name">Products</field>
<field name="res_model">product.product</field>
<field name="res_model">product.template</field>
<field name="domain">[('parties', 'in', Eval('active_ids'))]</field>
</record>
<record model="ir.action.keyword" id="act_party_product_keyword1">
@ -75,7 +80,7 @@
</record>
<record model="ir.action.keyword" id="act_product_party_keyword1">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="model">product.template,-1</field>
<field name="action" ref="act_product_party"/>
</record>

View File

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='description']" position="after">
<field name="related_sectors" widget="multiselection" colspan="6"/>
</xpath>
</data>

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/notebook" position="inside">
<page string="Sectors" id="sectors">
<field name="related_sectors" widget="multiselection"/>
</page>
</xpath>
</data>