How to call bank informations when there are more than one bank account - odoo

I'm working with Odoo 14 eCommerce module for shop and I'm customising email template (Sales: Order Confirmation).
I would like to show bank information which are already inserted on Accounting / Bank Accounts section of the company contact information such as; bank name, account holder name, account number etc.
I'm calling those values like this in the template:
${object.company_id.bank_ids.acc_holder_name}
${object.company_id.bank_ids.bank_name}
${object.company_id.bank_ids.acc_number}
When there is only one bank account defined, I get the right values without problem, but as soon as I add a second bank account, I get this error below:
Failed to render template : Expected singleton: res.partner.bank(2, 3)
I understand that there are ids of bank accounts, but I don't know what is the right way to indicate the id of the bank account which I want to get the value. Any idea?

You should loop over the bank records in the email template, this way:
% for bank in object.company_id.bank_ids:
<li>${bank.acc_holder_name}</li>
<li>${bank.bank_name}</li>
<li>${bank.acc_number}</li>
% endfor
If you want to do some action inside the loop depending on the ID of the bank account you should do this:
% for bank in object.company_id.bank_ids:
% if bank.id == 2:
<li>${bank.acc_holder_name}</li>
<li>${bank.bank_name}</li>
<li>${bank.acc_number}</li>
% endif
% endfor
However, performing an action depending on the database ID is not recommended since your module may won't work in any database. You must value yourself if it's worth it in this particular case.

Related

How to exclude value from google merchant file if it's "0"

i want to exclude one of the fields (sale_price) from usage if it's value in merchant file is '0' but Google merchant file rules are so confusing idk where to and how to do that because every time i want to use sale price in rule i can't just find something like "if sale_price is '0' do no use that field" or "set to "null"

Odoo - Can't Change Default Currency Company

I want to change the company currency by opening Setting->Companies->Currency. But when I already change the currency and hit save button, I get this warning dialog
You cannot change the currency of the company since some journal items already exist
How to solve this problem?
You cannot change the currency of the company since some journal items already exist
Some data are already created with the same currency, if you do not need that entry then simply delete it and then change the currency.
reference code - Source Code
#forbid the change of currency_id if there are already some accounting entries existing
if 'currency_id' in values and values['currency_id'] != company.currency_id.id:
if self.env['account.move.line'].search([('company_id', '=', company.id)]):
raise UserError(_('You cannot change the currency of the company since some journal items already exist'))
The error occurs because there was journal entries exist. You have at least 2 options if you must change the company currency:
Delete all journal entries.
Update all currency ID in all journal entries with new currency id directly via PostgreSQL.
Once option 1 or 2 done, then try again to change the company currency.

Matching an element in a column, to others in the same column

I have columns taken from excel as a dataframe, the columns are as follows:
HolidayTourProvider|Packages|Meals|Accommodation|LocalTravelVehicle|Cancellationfee
Holiday Tour Provider has a couple of company names
Packages, the features provided in each package are mostly the same like
Meals,Accommodation etc... even though one company may call it "Saver", others may call it "Budget". (each of column mostly follow Yes/No, except Local travel vehicle are again car names like Ford Taurus,jeep cherokee etc..
Cancellation amount is integers)
I need to write a function like
match(HolidayTP,Package)
where the user can give input like
match(AdventureLife, Luxury)
then I need to return all the packages that have similar features with Luxury by other Holiday Tour Providers, no matter what name they give the package like 'Semi Lux', 'Comfort' etc...
I want to give a counter for every match and display all the packages that exceed the counter by 3 or 4.
This is my first python code. I am stuck here.
fb is the total df I exported to
def mapHol(HTP, PACKAGE):
mfb = (fb['HTP']== HTP)&(fb['package']== package)
B = fb[mfb]
for i in fb[i]:
for j in B[j]:
if fb[i]==B[j]:
count+=1
I dont know how to proceed, please help me this is my first major project, I started on my own.

NULL values in Crystal Reports

I am trying to produce a Crystal Report showing MAIN and ALTERNATE contact details for our customers.
All works fine if the customer has both types of addresses (i.e. MAIN and ALTERNATE) but no report comes out at all for customers who only have a MAIN address. So, to summarise, all customers will have a MAIN address but only some will MAIN and ALTERNATE addresses.
I need to get the report to print sheets for all customers where or not the second address (in this case in our database as Addresses2.AddressType is ALTERNATE or NULL).
My selection formula is shown below:
{SubscriptionMembers.Current} and
{Categories.CategoryType} = "M" and
{SubscriptionMembers.MainSubscription} and
{Addresses.AddressType} in ["MAIN"] and
{Addresses2.AddressType} in ["ALTERNATE"] and
{Addresses.Country} = "United Kingdom" and
not {SubscriptionMembers.Lapsed} and
not {Contacts.Deleted}
I would recommend to use SQL Expression Field, containing something like (isnull({Addresses2.AddressType}, 'ALTERNATE')) and use this field in record selection formula - this way you do not depend on report options about handling NULL values etc.
Because only some have an 'Alternative address', the selection formula is only going to show customers with a 'main' AND 'alternative'.
I assume every customer has a main address
A way I would deal with this is take out {Addresses2.AddressType} in ["ALTERNATE"] and
and just drop the 'alternative' address details in the same section(group) as the main address.
As long as these are linked correctly it will display every customer from your other selection parameters, therefore will show 'main' and the customers who have an 'alternative' address.
How it should look:
Group - CustomerID
'MAIN' address details here 'ALTERNATE' address details here
Group - Details
'DATA' here
Since you need To get customer in either case then one way would be dont take address in record selection formula. Instead create a formula as to check null for address2
If isnull ({Addresses2.AddressType} in ["ALTERNATE"])
then your code
Else If (Addresses.AddressType} in ["MAIN"] or
{Addresses2.AddressType} in ["ALTERNATE"])
Then your calculation
This way you can handle easily

ROR find by sql to grab email addresses out of IBM iSeries (DB2)

We've been continuously working on this issue for a few months and not getting far with it. Since this was first asked, we changed the code (based on what the original developer for the site suggested), but we are still not getting where we need to be.
I'm relatively new to Ruby and am currently taking some courses to learn more about it, so please bear with me. We're using Ruby 1.9 and Rails 3.2 We use AS/400 for our database. We've tried using Active Record for this before, and it doesn't want to work because of our versions of Ruby and Rails being older combined with getting it to connect with the 400.
We have an online ordering site that you have to have an account set up to access. Depending on what type of account you are set up as, you might have to have your order approved by someone. I.e. if I am a drop ship account, my distributor has to approve what I'm ordering. The way it had been set up, the distributor wasn't getting any kind of approval email.
Each account that requires approval has x number of email addresses attached to it of people who are able to approve the order. We have been told that target_email needs to be a string, so we tried numerous ways of making it a string to no avail. As is, it's only sending the first two email, not the approval email. If we run target_email = Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"] in console, it returns the expected email addresses associated with that account. So we know that's working the way it should... but we're at a loss as to what is wrong with the rest of the code.
# notify Customer
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation", email_details)
target_email = Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
# Order Approval
if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD"
# If there is no distributor email address, the mailer model will substitute in the admin's email from their settings
target_email.each do | email_address | Mailer.deliver_order_distributor_approval_email(email_address, 'Coastal Pet Online Ordering<noreply#coastalpet.com>', "Order Confirmation Approval", email_details)
end
# notify Coastal staff
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation-Notify Staff", email_details)
end
I tried
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = act223").uniq
This works but it sends emails to multiple accounts why this would happen? I think I need to set a value for act223
act223 = "ACT223"
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = #{Contact.connection.quote(act223)}").uniq
this throws NameError (undefined local variable or methodact223' for #):`
in development.log.
Here is a link to the relevant table data if more table information is needed just let me know and I can add it to that page. I am looking to do some sort of a join of a field from another table. In this same model I have SignOn.prefdstw1 which gets me the same account number is there a way to Join this field in the query with the 400?
Any help or suggestions would be greatly appreciated! Thank you in advance!
find_by_sql always returns an array of model objects, so
Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]
is not an array of email addresses - it's an array of Contact objects, with only one object
You could either extract the email addresses from this, using something like
Contact.find_by_sql(["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]).collect do |contract|
contact.emal23
end
I'm not entirely sure what rails will do to the uppercased column name.
If you don't want to instantiate a whole Contact object just to get the email you could also do
Contact.where("ACT223 = ''").pluck('EMAL23')
which would return an array of emails, assuming that Rails knows that the correct table to use for this is WEBOEL23 - it's not clear to me whether that is the table for Contact (and thus you've use set_table_name to configure this) or whether Contact is just a random model unrelated to that table.
You could also drop down a level and do
Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
which will also return an array of email addresses.
Inside the each loop, target_email is a bareword variable (without quotes), but the first argument to the mailer is the string (within quotes) 'target_email'.
Remove those quotes to get to this (whitespace added for readability):
target_email.each do | email_address |
Mailer.deliver_order_distributor_approval_email(
email_address,
'Coastal Pet Online Ordering<noreply#coastalpet.com>',
"Order Confirmation Approval",
email_details
)
end
Then the mailer should have access to the email address.