Comments (7)
what you posted looks perfectly fine to me. I assume you open this in some wizard where you fill in defaults for the from and to dates? The thing is that web_widget_x2many_2d_matrix
is only a widget, it takes care of displaying stuff. You need to take care of the content yourself.
So if you give the field content like
def default_get(self):
defaults = super(yourmodel, self).default_get()
defaults['task_id'] = [
(0, 0, {
'employee_id': e,
'project_id': p,
'planned_hours': h.
})
for e, p, h in {a function that generates values for all employee/project combinations}
you should see something more intersting
from web.
@hbrunn , Thanks for your reply.
I tried what you advised me and this is my new view:
In this code i used the zip function only for save time
def default_get(self, cr, uid, fields, context=None):
defaults = super(Manager,self).default_get(cr, uid, fields, context=None)
employee_obj = self.pool.get('test.matrix.employee')
employee_ids_list = employee_obj.search(cr, uid, [], context=context)
employee_names_list = [rec.name for rec in employee_obj.browse(
cr, uid, employee_ids_list, context=context)]
project_obj = self.pool.get('test.matrix.project')
project_ids_list = project_obj.search(cr, uid, [], context=context)
project_names_list = [rec.name for rec in project_obj.browse(
cr, uid, project_ids_list, context=context)]
defaults['task_id'] = [
(0, 0, {
'employee_id': e,
'project_id': p,
'planned_hours': h
})
for e, p, h in zip([employee_names_list],[project_names_list],[12,22,21])
]
return defaults
This seems good, but the only thing that i don't understand is about the values of the dictionary 'defaults['task_id']', I mean:
defaults['task_id'] = [
(0, 0, {
'employee_id': e, #e should be a list of employees o a single employee?
'project_id': p, #p should be a list of projects o single project?
'planned_hours': h
})
]
That's all, thanks for your advices!
from web.
a couple of things:
project_id
andemployee_id
are declared as Many2one in your example, so pass the ids you have- the way you create your data, you'll never get a full matrix. Do something like
defaults['task_id'] = [
(0, 0, {
'employee_id': e,
'project_id': p,
'planned_hours': 0,
})
for e in employee_ids_list
for p in project_ids_list
]
it's two dimensional after all, so two loops.
- you don't need the names, the widget looks that up by itself and if I remember correctly, even makes the names links that open the referenced object
Would you care to write up your findings in a PR on the addon's README.md? Then everyone has a simpler start than you had.
from web.
@jjrevilla is your question answered?
from web.
Yes, thanks so much for your help and time now i have a better understanding of odoo's widgets. I'm sorry for late response.
from web.
@hbrunn
Hi, I am having basically the same issue except I want to use it for the Landed Cost Valuation Adjustment where in value_x I want the Cost Lines and in the value_y I want the product_ids. So I had this but the form do not show at all. The values in the Many2Many are populated when I hit the compute button in the landed cost. I'm kinda lost in the process. Can you guide me?
class Load(models.Model):
_name = 'load.load'
_rec_name = 'load_number'
load_lines = fields.One2many(comodel_name='load.line',
inverse_name='load_id',
string='Load lines')
adjustment_lines_ids = fields.Many2many( comodel_name='load.adjustment.fees.load.lines', string='Fee Lines', compute='_compute_fee_lines')`
@api.depends('load_lines')
def _compute_fee_lines(self):
fee_lines = []
for line in self.load_lines:
fee_lines.extend(line.adjustment_fees)
return fee_lines`
def compute_landed_cost(self):
AdjustementLines = self.env['load.valuation.adjustment.lines']
AdjustmentFees = self.env['load.adjustment.fees']
AdjustementLines.search([('cost_id', 'in', self.ids)]).unlink()
AdjustmentFees.search([('load_id', 'in', self.ids)]).unlink()
AdjustmentFeeLines = self.env['load.adjustment.fees.load.lines']
digits = dp.get_precision('Product Price')(self._cr)
towrite_dict = {}
for cost in self.filtered(lambda cost: cost.load_lines):
total_qty = 0.0
total_cost = 0.0
total_weight = 0.0
total_volume = 0.0
total_line = 0.0
all_val_line_values = cost.get_valuation_lines()
lines = []
for val_line_values in all_val_line_values:
for fee_name, fee_value in val_line_values.iteritems():
fee = self.env['load.adjustment.fees'].create( {'load_id': cost.id, 'name': fee_name})
for load_line in cost.load_lines:
lines.append((0, 0, {
'value_x': fee.id,
'value_y': load_line.id,
'adjustment_value': 0
}))
fee = fee.update({'adjustment_lines_ids': lines}
class AdjustmentLineFees(models.Model):
_name = 'load.adjustment.fees'
_description = 'Stock Valuation Adjustment Fees'
load_id = fields.Many2one(
'load.load', 'Landed Cost',
ondelete='cascade', required=True)
adjustment_lines_ids = fields.Many2many(
comodel_name='load.adjustment.fees.load.lines', string='Fee Lines')
adjustment_fees = fields.One2many(comodel_name='load.adjustment.fees.load.lines',
inverse_name='value_x',
copy=True,
string='Load lines')
name = fields.Char('Fee', required=True)
class AdjustmentFeesToLoadLines(models.Model):
_name = 'load.adjustment.fees.load.lines'
_description = 'Stock Valuation Adjustment Fees To Load Lines'
load_id = fields.Many2one(related='value_y.load_id')
value_x = fields.Many2one('load.adjustment.fee', 'Fee', required=True)
value_y = fields.Many2one('load.line', 'Load Line', required=True)
adjustment_value = fields.Char('Value')
<div class="oe_clear"/>
<separator string="Valuation Adjustments"/>
<field name="adjustment_lines_ids"
widget="x2many_2d_matrix"
field_x_axis="value_x"
field_y_axis="value_y"
field_value = "adjustment_value"
field_att_disabled="disabled"
x_axis_clickable="1"
y_axis_clickable="1"
/>
<div class="oe_clear"/>
<separator string="Valuation Adjustments"/>```
from web.
first, don't use the widget at all to inspect the values with a normal many2many widget. then, check if the values in there will form a balanced matrix at all, and then post whatever get_value
gets as arguments
from web.
Related Issues (20)
- Missing web_widget_text_markdown for newer versions HOT 3
- I would really like to get this module on version: 14.0 HOT 1
- causes a problem where the toolbar does not appear when text is selected in the editor within a popup window. web_responsive.scss file, specifically in lines 373-377. HOT 5
- [16.0] web_remember_tree_column_width: issues with HTML fields HOT 1
- [16.0] web_company_color: not working if not all colors are filled HOT 4
- [16.0] web_chatter_position: Button to switch between sided and bottom views HOT 2
- [16.0] web_responsive: document_url module is not working properly when installed
- [17.0] web_responsive: Main document preview is activated by default HOT 4
- [17.0]Can this module be migrated to the 17.0 version ?? HOT 6
- column width in tree view HOT 2
- [11.0] error install web_responsive module HOT 1
- [16.0] web_advanced_search bug HOT 7
- [16.0] web_responsive: The web responsive will revert back to odoo base behaviour when we reload the page from website. HOT 3
- [16.0] web_refresher: Refresh action returns to create a new record when already has been created the record HOT 3
- [16][web_responsive] Bold doest whows as normal text in HTML fields HOT 3
- web_widget_x2many_2d_matrix 17.0 can not edit the value
- [16.0] web_widget_x2many_2d_matrix: Error when value is Date HOT 1
- [16.0] web_responsive: The web responsive will revert back to odoo base behaviour when we reload the page from website. HOT 4
- [16.0] web_pivot_computed_measure - error when divide by 0
- [17.0] web_widget_x2many_2d_matrix - Domain is not taken into account
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web.