Adding lookups to given view - yii

I'm just getting into Yii. I have a simple relational db. I have a "client" table related to "orders" table (client:id to orders:client_id). If I build my CRUD for orders i naturally see client_id, however I'd rather add a lookup for client name somehow
I have found how to do this on new and update _forms by adding a dropDownList. The list based views seem a little more complex. I can see that actionIndex() in the controller is gathering data and passing it to index.php, finally through to _view, but I can't find any help on where and how I should break into this with my lookup returning the client name
I'd appreciate any help
thanks

Check the Yii documentation about relations. You will need to create a relation in your orders table, lets call it client, Then in your list view where it generates client_id you can put client.name instead. Now you will need to make sure that you have the appropriate label because in the generated model it will only have a label for client_id, and you need a label for client.name. Yii will guess, or you can add it, or you can modify the label for client_id, and instead of using client.name in the view you can use
array(
'name'=>'client_id',
'value'=>$model->client->name,
)
I tend to gravitate towards more explicit definitions rather than shortcuts, but to each his own.

Related

Odoo 15 Find tax_ids Inside the account.move.line (Invoice) Model

Good day, hope everything's well.
I'm trying to find the value of tax_ids (Many2many field) inside the account.move.line model but i can't seems to find anything. I already access the psql of the database but i cant find tax_ids too.
I accessed that account.move.line model with ORM like this :
def _post(self, soft=True):
for move in self:
....
account_move_line = self.env['account.move.line'].search([('id', '=', int(move.id))])
print(account_move_line.tax_ids) #this find nothing
could someone please elaborate how is it possible to access id of the tax that applied to, in this case, an invoice line record?
Edit : Sometimes this ORM fetching the ID and sometimes it doesn't. But most likely it's not fetching.
I'm trying to find the value of tax_ids (Many2many field) inside the
account.move.line model but i can't seems to find anything. I already
access the psql of the database but i cant find tax_ids too.
tax_ids in account.move.line model is a Many2Many field, which is stored separately as another table in the database. This kind of relation field mostly be named something like this (main_table)_(related_table)_rel (ignore the parentheses). For example, this particular case's table is account_move_line_account_tax_rel since its main table is account_move_line and the related table for that specific field is account_tax. Inside the relation table, you will almost always find 2 fields mapping both ids together. For this case, it is going to be account_move_line_id and account_tax_id.
I accessed that account.move.line model with ORM like this :
def _post(self, soft=True):
for move in self:
....
account_move_line = self.env['account.move.line'].search([('id', '=', int(move.id))])
print(account_move_line.tax_ids) #this find nothing could someone please elaborate how is it possible to access id of the tax
that applied to, in this case, an invoice line record?
Edit : Sometimes this ORM fetching the ID and sometimes it doesn't.
But most likely it's not fetching.
Accessing a field via ORM always works as you intended if it is implemented correctly. In your code, you are searching account_move_line by id but you are trying to search it with move.id, which I assume it is account_move since you got the data sometimes. If you can access the lines that you want correctly, you will see that account_move_line.tax_ids will always give you the correct tax_ids. From what your code looks, I think you are trying to search the lines by its account_move. Therefore, your domain should be [('move_id', '=', int(move.id))] instead.

Is it possible to use a my SQL inner join query inside my ASP.NET WEB API app directly, or is it better to translate, if so how can it be done?

I'm working on my first (kinda) big personal project and I am stuck. I have 4 tables, 3 of which have foreign keys linking into tbl_model_details. All tables are listed below.
tbl_model_details
tbl_model_type
tbl_model_name
tbl_model_scale
Ideally I want to show data through my controller with HTTP Get. I can get Postman to to return data from my controller using _context.tbl_model_details.ToList();
Currently Postman is showing the id's for the other tables, but want them to show data from other columns within those tables instead of the id.
Within SQL I was able to build this query which displays the information I would like from the other tables, Is there an equivalent that I could make to run inside my controller? Or is there a way I can use this query that I have already made?
SELECT model_scale, model_name, info, picture, model_type, part_number, amount_owned, modified, limited_addition, date_purchase, price_paid, upc
from tbl_model_details
join tbl_model_type
on tbl_model_details.type_id = tbl_model_type.type_id
join tbl_model_name
on tbl_model_details.name_id = tbl_model_name.name_id
join tbl_model_scale
on tbl_model_details.scale_id = tbl_model_scale.scale_id
Any help from you guys would be great.
Thanks
You can use Entity Frameworks LINQ Include. This will allow you to include the sub-models in the same query:
_context.tbl_model_details
.Include(details => details.tbl_model_type)
.Include(details => details.tbl_model_name)
.ToList();
Without knowing your relationships, DBSet and Model setups, I can say that the statement will look exactly like the one I mentioned, but this may help you get on the right track.
This will allow you to later retrieve data from the sub-models:
#Model.tbl_model_scale.model_scale;

How to create just a view in odoo9 that does not save data in a model?

I am working in odoo9. Now I needed a view that permits the user to select partner and get his sale history.
Now I created a model "sale.history" but it saves the selected data as a record in db. I really don't need this.
How can I create a view for this.
Please also see this image.
You have two options for such views/reports.
Use TransientModel instead of Model for the model inheritance. Transient model records in database will be deleted by a frequently running cron job. The email message PopUp/Wizard is a nice example for that.
Write your own report (database view) for sales order. Actually there already is one report for that: Reporting/Sales/Sales Analysis. The model for that report is sale.report if you want to know, how it's done.
Aside from using a TransientModel (old api) or AbstractModel (new api)...you can simply set the store property of field to false, that way your field will never be persisted to the database, it will simply be a 'view field'.
class sale_history(model.Model):
_name='sale.history'
partner = fields.Many2one('res.partner', store=False)
The partner field will never get saved to the database
You can use store=False on the field in the model (as danidee suggested).
You can also overwrite the create method on the model.
Question - what is the purpose of the "sale.history" model? If it does not store any data at all then you may be better off creating a new view against "res.partner" rather than creating a new model.

When relating 3 entities in CRM 2011 using Advanced Find only 2 entities show up in edit columns

I'm trying to create a view in CRM 2011 that will show a few columns from Customers (Account), Orders (SalesOrder), and Order Products (SalesOrderDetail). I already know I need to start at the child-most entity so under Advanced Find I select "Order Products" under Look for. When I do this I'm able to select columns from Orders but unable to select columns from Customers.
Is this even possible to accomplish in CRM?
I'm trying to create the following result set:
Account.Name,
Account.Email,
SalesOrder.OrderNumber,
SalesOrderDetail.NetAmount,
SalesOrderDetail.ShipDate
I verified that you cannot manually add a second link within a view query. To my knowledge it is also not possible to add these columns though javascript. You can get the account name in your view simply by using the account lookup on the Order. If you need for the account email to also be in the view, then I suggest you add this field to the order entity and populate it with post callout logic on the account.
I Second Zach’s idea, but suggest adding a direct relationship between customer and orderdetail . This way you can use fetchxml to show account.email or any other account.* for that matter.
The downside is you’ll need to sync order.customer changes to orderdetail.customer.
The better option is to simply create a report and show that in an iframe or a webresource.
This is not possible even if we edit the fetch xml it wont work

Rails 3 find model attribute with foreign key in another model

I have two models, Reports(belongs to client) and Clients(has many reports). A Client has an attribute or column called "specialty". What I'm trying to do is to be able to call and display the Client.specialty attribute for that particular #client when inside the show page of a #client's Report. In my Report model I do have a "client_id" foreign key. I have no idea how to do this, I've gone about this far:
#report.client_id
This obviously displays a number, but I don't know how to go any further, In my noob ways I want to do something like this:
#report.client_id.specialty
But that doesn't work obviously. How do I do this?
why not the following?
#report.client.specialty